Vuejs 购物车项目

vue 邓文星
文章标签: vue

购买功能

实现思路:点击购买将商品添加到购物车,先循环对比看要添加的商品是否已经存在与购物车,如果存在,只加数量,不存在则添加

实现代码

 add(val) { //购买 ,这里我是传了对应的item 过来    
        var result=true;      
            for(var i of this.goods){
                if(val.book==i.book){ //判断名称是否已经存在       
                         i.number++;                   
                         result=false;                
                          break;               
                   }
            }
            if(result){//如果没则添加
                this.goods.push({
                    book:val.book,
                    score:val.nowPrice*10,
                    marketPrice:val.oldPrice,
                    dangPrice:val.nowPrice,
                    discount:Math.ceil(val.nowPrice/val.oldPrice*100),
                    number:'1'
                });
            }
        },

删除功能

实现思路:点击删除,将对应的商品从list数组中删除,根据传过来的index,调用数组的splice方法

del(i){ //删除 
   this.goods.splice(i,1);
},

还能输出{{restrictNumber}}个字符  
  • {{reply.author}}

    {{CommonUtil.formateDate(reply.ac_CommentDate).shortTime}}
  • 回复了{{Comments.author}} :