1.准备变量
state: {
inputValue: 'aaa',
}
2.mutations方法
mutations: {
// 为store中的inutValue赋值
setInputValue (state, val) {
state.inputValue = val
}
}
3.vue中引入变量inputValue
computed: {
...mapState(['inputValue'])
}
4.vue组件中通过setInputValue方法将新值传给store
methods: {
handleInputChange (e) {
this.$store.commit('setInputValue', e.target.value)
}
}