1.获取状态数据1.普通获取:在computed属性computed中将state中的数据作为函数返回:{cont(){rteurnthis.$store.state.num}}2.获取mustache语法中的状态数据:
{{$store.state.num}}
3.函数辅助获取状态数据:在...mapstate()...mapstate(['num'])中传入一个字符串数组4.Modules为拆分模块,包裹在对象、键值对、值中都是箭头函数...mapstate({num:state=>state.num})2.调用mutation方法1.在组件中普通调用store.commit()//store.commit('方法名')2.函数-辅助调用,传入一个字符串方法名数组in...mapmutations//1.无参数...mapmutation(['add'])//2。如果需要传递参数,在3.modules模块化拆分出来的事件中调用this.add(需要传递的参数),对象被包裹,键值对方法...mapmutations({propertyname:'文件夹名/方法名'})//如果要传递参数,在事件中this.propertyname(要传递的值)3.调用actions方法1.通过$store.dispatch()方法普通调用//vuex中的mutations:{getadd(state,payoad){state.num=payoad}}actios只是异步提交mutationsmethodactions:{add(context,payoad){//异步代码settimeout(()=>{//Submitmutations,通过commitcomtext.commit('mutationsmethodname',payoad)},1000)}}//在组件中调用this.$store.dispatch('异步方法名',要传递的值)2.函数辅助调用,将字符串方法名称数组传递给...mapactions//1。没有传参数...mapactions(['异步方法名'])//2.如果要传递参数,在eventCallthis.Asynchronous方法名(传递的参数)3.modules模块拆分出来,包裹在对象中,以键值对的形式...mapActions({propertyname:'文件夹名/方法名'})//如果要传递参数,在事件中this.propertyname(要传递的值)