mui('.mui-scroll-wrapper').scroll({
deceleration: 0.0005 //flick 减速系数,系数越大,滚动速度越慢,滚动距离越小,默认值0.0006
});
//每次进入网站调用本地存储
var car = JSON.parse(localStorage.getItem('car') || '[]')
//创建vuex
var store = new Vuex.Store({
state: { //this.$store.state.****
car: car, //储存购物车的商品数据
},
mutations: { //this.$store.commit("方法名称",参数 )
addcomm(state,obj){
var flag = false
state.car.some( item =>{
//如果有此商品则增加数量
if(obj.id == item.id){
item.count += parseInt(obj.count);
flag = true
return true
}
}
)
if(!flag){
state.car.push(obj)
}
//添加到本地储存
localStorage.setItem("car",JSON.stringify(state.car))
}
},
getters: { //this.$store.getters.***
getcount(state){
var i = 0;
state.car.forEach(
item =>{
i +=item.count
}
)
return i
}
}
})