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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ohh, i found a solution for this.
Using the store.registerModule.
Sorry by the flood.