//////////////////////////////////////////////////////////////
//1.store的变量定义和赋值方法---在store的index.js里面
//////////////////////////////////////////////////////////////
state: {
globalloginvisible: false, //用于控制token失效后的login弹窗开关
creditapplydata: {} //从服务器获取每笔融资需求的数据
},
mutations: {
// 修改变量的方法
setgloballoginvisible(state, data) {
state.globalloginvisible = data
}
},
//////////////////////////////////////////////////////////////
//2.方法的调用
//////////////////////////////////////////////////////////////
if (response.data.msg == 419) {
store.commit("setgloballoginvisible", true)
}
//////////////////////////////////////////////////////////////
//3.监控store的数据,要用computed的一个函数来操作
//////////////////////////////////////////////////////////////
computed: {
watchgloballoginvisible() {
return this.$store.state.globalloginvisible;
},
},
watch: {
watchgloballoginvisible(newval) {
//你需要执行的代码
// console.log(newval, "监控globalloginvisible");
this.fvisible = newval;
},
},
【vuex】store的用法和全局监控
最新推荐文章于 2024-07-01 17:07:49 发布