store.js:
store = new Vuex.store({ state:{ inputVal: '' }, mutations:{ setInput (state, newVal) { state.inputVal = newVal } } })
页面中绑定:
<template>
<div>
<input v-model = 'storeVal'>
</div>
</template>
<script>
export default {
computed: {
storeVal (e) {
get() {
return this.$store.state.inputVal
},
set(newVal) {
this.$store.commit('setInputVal', newVal)
}
}
}
}
</script>