vuex + vuelidate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
import { validationMixin } from 'vuelidate' | |
import { required, minLength } from 'vuelidate/lib/validators' | |
export default function (store) { | |
const validator = new Vue({ | |
mixins: [ | |
validationMixin | |
], | |
computed: { | |
name () { | |
return store.getters['user/name'] | |
} | |
}, | |
validations: { | |
name: { required, minLength: minLength(3) } | |
} | |
}) | |
const module = { | |
namespaced: true, | |
state: { | |
name: '', | |
}, | |
getters: { | |
name (state) { | |
return state.name | |
}, | |
$v (state) { | |
// don't expose api | |
return Object.assign({}, validator.$v) | |
} | |
}, | |
actions: { | |
$touch () { | |
validator.$v.$touch() | |
}, | |
name ({ commit }, value) { | |
commit('name', value) | |
} | |
}, | |
mutations: { | |
name (state, value) { | |
state.name = value | |
} | |
} | |
} | |
return module; | |
} |
Ohh, i found a solution for this.
Using the store.registerModule.
Sorry by the flood.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@autumnwoodberry
Hey man, thanks for share this solution.
I have a question in implementation.
Who pass the store as param to the module factory?
That would help me a lot. Thanks