vuex-map-model
More elegant one-way data flow using Vuex with v-model command
Install
npm:
npm install --save vuex-map-model
or yarn:
yarn add vuex-map-model
Usage
Basic example
Typically, you can simply import vuex-map-model
into the component and add mutaion function to the corresponding store.
Component
Store
@/store/module/cars:
namespaced: true state: carUnique: '' mutations: // Once the `this.carUnique` changed, `vuex-map-model` will // commit a payload to the Vuex store // // @example // <= this.carUnique = 'TRS012333G7' // => payload: 'TRS012333G7' { statecarUnique = payload } actions: ...
Nested fields
In some cases, you need to define multiple fields at the similar situation, such as the query boxes for the list, then you can use arrays to merge updates for fields quickly.
Component
Store
@/store/module/cars:
const initState = search: carUnique: '' carStatus: '' loading: false ... namespaced: true state: mutations: // Once the `this.carUnique` or `this.search` changed, `vuex-map-model` will // commit a payload to the Vuex store // // @example // <= this.carUnique = 'TRS012333G7' // => payload: { carUnique: 'TRS012333G7' } // <= this.search = { carStatus: 2 } // => payload: { carStatus: 2 } { Object } { statesearch = search } actions: ...
Attention
We strongly oppose the use in places where there is no v-model, please reference Two-way Computed Property
License
MIT