commit 同步操作
改变流程: 页面触发 — mutations — state
存储:
1.只有一个根文件(index.js)
this.$store.commit('名称',传入的值)
2. 模块化时:
this.$store.commit('文件名+mutations中的函数名',传入的值)
例如:this.$store.commit('area/SET_NAME','我是三九感冒灵')
取值:
1.只有一个根文件时
this.$store.state.属性名
2.this.$store.state.文件名.属性名
例如:this.$store.state.area.name
dispatch 异步操作
改变流程: 页面触发 — actions — mutations — state
存储:
1.只有一个根文件(index.js)
this.$store.dispatch('名称',传入的值)
2. 模块化时:
this.$store.dispatch('文件名+mutations中的函数名',传入的值)
例如:this.$store.dispatch('area/getRoles','我是三九感冒灵')
取值
1.只有一个根文件时
this.$store.getters.属性名
2.模块化时
this.$store.getters.属性名
例如:this.$store.getters