一:vue-elementui-template的vuex简单使用
1、在store/modules/user.js 的mutations中添加
SET_WARMSTATUS: (state, data) => { state.warmStatus = data }
2、在action里添加
warmStatus({commit, state}, data) { commit('SET_WARMSTATUS', data) },
再在store/getter.js 中添加定义
3. 在组件内修改两种方法,关于action和mutations的区别具体看官网https://vuex.vuejs.org/zh/guide/
1)修改action
this.$store.dispatch('user/warmStatus', '5')
2)修改mutations
this.$store.commit('user/SET_WARMSTATUS', '5')
二:坑
由于我是用window.open打开的页面,所以已经脱离了原来的vue实例,在里面操作vuex没有用了。。
三:解决办法
可以通过监听localstorage的方法
1)在操作的页面
localStorage.setItem('warmStatus', '111')
2)在需要监听的页面的created里
window.addEventListener('storage',(event) => { // 你的操作 })