我有点笨拙,一切工作正常,除了我不知道如何仅在Submit单击按钮时运行验证。现在,当您开始提供任何输入时,它会将触摸的字段标记为红色,我希望它等待着,直到用户想要提交填写的表单为止。
这是我到目前为止的工作:
Vue.use(window.vuelidate.default)
const { required, minLength, sameAs } = window.validators
new Vue({
el: "#app",
data: {
user: {
login: '',
password: '',
repeatedPassword: ''
}
},
validations: {
user: {
login: {
required,
minLength: minLength(5)
},
password: {
required,
minLength: minLength(8)
},
repeatedPassword: {
required,
sameAs: sameAs('password')
}
}
}
})
Run Code Online (Sandbox Code Playgroud)
input {
border: 1px solid silver;
border-radius: 4px;
background: white;
padding: 5px 10px;
}
.error {
border-color: red;
background: #FDD;
}
.error:focus {
outline-color: #F99;
} …
Run Code Online (Sandbox Code Playgroud)