store缓存
2023/6/14原创小于 1 分钟约 138 字
store基础应用
导入
import {
mapState,
mapMutations,
mapActions
} from 'vuex'
属性使用
computed: {
...mapState(['testvuex','appid'])
}
设置属性
methods方法内
...mapMutations(['setTestTrue']),
...mapMutations(['setTestFalse']),
...mapMutations(['setAppId']),
...mapActions(['demo']),
this.setAppId('ab123')
在store 文件中添加方法
mutations: {
setAppId(state,appid1,app){
console.log(appid1)
state.appid=appid1
}
}
说明
state=》相当关于data this.$store.state.属性值
getters=》相当于computed this.$store.getters.status
mutations=》类似method方法,this.$store.commit("updateUserData",'admin'),
也可在vue中导入mapMutations方法
actions=》可以同时执行多个mutations方法