// 父组件
computed: {
rangeCode: {
get () {
return this.$store.state.rangeCode
},
set (val) { return val }
}
},
methods: {
rangeClick (idx) {
this.$store.commit('setRangeCode', idx)
}
}
// vuex
const store = new Vuex.Store({
state: {
rangeCode: 0
},
mutations: {
setRangeCode (state, code) {
state.rangeCode = code
}
}
})
export default store
// main.js
import store from '@/state/index' // 根据自己的路径引入
Vue.prototype.$store = store
使用vuex保存状态
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…