store文件夹下index.js
const state = {
upAndDown: ''
};
store文件夹下mutations.js
setUpAndDown(state, val) {
state.upAndDown = val;
}
需要改变全局变量 setUpAndDown就是上面的方法名
this.$store.commit('setUpAndDown', '1');
监听全局变量发生变化执行方法:
watch: {
'$store.state.upAndDown': {
handler(newName, oldName) {
if (newName === '1') {
this.rs1 = this.newresult.reverse().slice(0, this.limit);
} else {
this.rs1 = this.newresult.reverse().slice(0, this.limit);
}
console.log(oldName);
},
immediate: true,
deep: true
}
}