Combine data object and validation schema in one declaration
Vuelidate docs
- Install vuelidate and vuelidate-forms
npm install vuelidate vuelidate-forms
- Import and write Vue.use
import Vue from 'vue'
import Vuelidate from 'vuelidate'
import VuelidateForms from 'vuelidate-forms'
Vue.use(VuelidateForms)
Vue.use(Vuelidate)
Important: you should connect VuelidateForms before Vuelidate.
new Vue({
forms: {
test: {
field: {
required
},
anotherField: {
required,
numeric
}
}
}
})
Is equal to
new Vue({
data: {
test: {
field: null,
anotherField: null
}
},
validations: {
test: {
field: { required },
anotherField: { required, numeric }
}
}
})
new Vue({
forms: {
test: {
field: 'test',
anotherField: {
required,
numeric,
$value: 5
}
}
}
})
Is equal to
new Vue({
data: {
test: {
field: 'test',
anotherField: 5
}
},
validations: {
test: {
anotherField: {
required,
numeric
}
}
}
})
new Vue({
forms: {
test: {
list: {
minLength: minLength(5),
$each: {
field: {
required
},
anotherField: {
required,
numeric
}
}
}
}
}
})
Is equal to
new Vue({
data: {
test: {
list: []
}
},
validations: {
test: {
list: {
minLength: minLength(5),
$each: {
field: {
required
},
anotherField: {
required,
numeric
}
}
}
}
}
})
- Finish plugin
- Write tests