1 :映射获取:辅助函数
mapGetters:辅助函数mapGetters:辅助函数仅将store的getter映射到本地计算属性。
1:import { map getters } from ' vuex '2: export default { computer : }//使用对象展开运算符将getter与computer对象混合. map
Vuex的mutation与事件非常相似。 对于每个mutation,字符串事件类型 (type)和回调函数 (handler)此回调函数是实际进行状态更改的位置,并接受state作为第一个参数
更改3:store中的数据:
conststore=newvuex.store ({ state : { count : },mutations:{increment(state ) /变更状态state.count } }} )
此选项类似于事件注册。 “在触发类型increment的mutation时调用此函数。
”要唤醒mutation handler,必须在相应的type中调用store.commit方法:
store.commit(increment )5:提交负载(payLoad ) ) ) ) ) ) ) )。
store.commit中的其他参数,即mutation的载荷(payload) (Payload: 载荷参数)
//mutations : (increment (state,n ) state.count=n ) ) store.comMIT ) ' increment ',10 )7)如何提交对象样式
发送mutation的另一种方法是直接使用包含type属性的对象。
store.com MIT (type : ' increment ',amount: 10} )8:如果使用提交对象样式的方法:将整个对象作为负载传递给mutation函数; 所以handle不会变。