针对此案例,我使用 vue-cli 来实现,将购物车和地址栏写成了两个子组件,将vue-router 替换成 axios,正在学 vue-cli 同学,欢迎一起交流,代码中均有详细注释。
链接: https://github.com/itPoet/vue-cli-shoppingcart
                链接: https://github.com/itPoet/vue-cli-shoppingcart
                    
                    2018-03-22
                
            selectedProduct: function (item) {
if(!item.checked){
// Vue.set(item,"checked",true)
this.$set(item,"checked",true)
}else{
item.checked = !item.checked
}
//实现了单选全部按钮 全选被选中
this.checkAllFlag = this.productList.every((val)=>{
return val.checked == true
})
}
                if(!item.checked){
// Vue.set(item,"checked",true)
this.$set(item,"checked",true)
}else{
item.checked = !item.checked
}
//实现了单选全部按钮 全选被选中
this.checkAllFlag = this.productList.every((val)=>{
return val.checked == true
})
}
                    
                    2018-03-22
                
            参看评论的答案后改了下:
var _this = this,
arr = []
len = this.productList.length;
this.productList.forEach(function(item,index){
if (item.checked) {
newArr = arr.push(index);
}
});
if (newArr == len) {
_this.checkAllFlag = true;
}else{
_this.checkAllFlag = false;
}
                var _this = this,
arr = []
len = this.productList.length;
this.productList.forEach(function(item,index){
if (item.checked) {
newArr = arr.push(index);
}
});
if (newArr == len) {
_this.checkAllFlag = true;
}else{
_this.checkAllFlag = false;
}
                    
                    2018-03-19
                
             
             
        







