我在Laravel刀片中插入了cdn中的vue.js和vee-validate.js文件。
之后在脚本标记中插入了Vue.use(VeeValidate);
。
在此步骤之后,我(从此步骤开始)。最后我在脚本标签中有vue obj进行验证:
new Vue({
el: '#app',
created() {
this.$validator.extend('bacon', {
getMessage: field => {
return `Field ${field} does not contain the word 'bacon'!`;
},
// Returns a boolean value
validate: value => {
return value.indexOf('bacon') !== -1;
}
});
},
methods: {
validateBeforeSubmit(e){
this.$validator.validateAll().then((result) => {
if (result) {
alert('From Submitted!');
return;
}
alert(errors.length);
alert('Correct them errors!');
});
}
}
});
所有这些都需要在Laravel的刀片文件中完成。