A组件:
this.$store.dispatch('setYearDate', 修改后的值)
B组件:
import store from '@/store/modules/home'
watch:{
'$store.state.yearDate':function(val){
//监听到变化后做的操作console.log('变化后的值:',val)
}
},created(){
this.selYear=store.state.yearDate;
}
store/module/home.js
import Vue from 'vue'
import store from '../index'const avation = {
state: {
yearDate:' '
},
mutations: {
SET_YearDate: (state, data) => {
state.yearDate = data
},
},
actions: {
setYearDate ({ commit },data) {
commit('SET_YearDate', data);
}
}
}export default home
store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import home from './modules/home'
import getters from './getters'Vue.use(Vuex)
export default new Vuex.Store({
modules: {
home
},
state: {},
mutations: {},
actions: {},
getters
})