一个简单的vuex-playList-2

import vue from 'vue'
import vuex from 'vuex'
vue.use(vuex)
export const store = new vuex.Store({//按名导出
state:{
products:[
{ name : "马云" , price : '1000' },
{ name : "马化腾" , price : '500' },
{ name : "马冬梅" , price : '200' },
{ name : "马荣" , price : '100' },
]
},
getters:{
getpro(state){
return state.products
}
},
mutations:{
reduce(state,playLoad){
state.products.forEach(item => {
return item.price = item.price -= playLoad
})
}
},
actions:{
reducePrice(context,playLoad){
setTimeout(() => {
context.commit('reduce',playLoad)
 
}, 1000);
}
}
 
})

posted on 2018-12-25 22:30  码农_9527  阅读(71)  评论(0编辑  收藏  举报

导航