vuex-map-state-two-way
Installation
$ npm install @shimochi/vuex-map-state-two-way --save
Usage
<template>
<form>
<input v-model="name">
<input v-model="email">
</form>
</template>
<script>
import { mapStateTwoWay } from 'vuex-map-state-two-way';
export default {
computed: {
...mapStateTwoWay('user', ['name', 'email'])
}
}
</script>
export default {
namespaced: true,
state: {
name: null,
email: null
},
getters: {
name: state => state.name,
email: state => state.email
},
mutations: {
name (state, name) {
state.name = name
},
email (state, email) {
state.email = email
}
},
actions: {
setName ({ commit }, value) {
commit('name', value)
},
setEmail ({ commit }, value) {
commit('email', value)
}
}
}
License
The vuex-map-state-two-way is open source software licensed under the MIT license.