mapState for v-model
$ npm i map-state-vmodel
- in *.vue
<template>
<div>
<input v-model="userName" />
</div>
</template>
<script>
import {mapStateVModel} from 'map-state-vmodel'
export default {
computed: {
...mapStateVModel('user', [
'userName'
])
}
}
</script>
- in store file
user.js
import {createSetters} from 'map-state-vmodel'
const state = {
userName: 'wangdahoo'
}
const mutations = {
...createSetters(state)
}
const getters = {}
const actions = {}
export default {
namespaced: true,
state,
mutations,
getters,
actions
}
That's it.