The official example of
is to put a string directly, but you can v-bind it to a variable, and the text of the variable change prompt changes.
<van-field
v-model="phone"
label=""
placeholder=""
:error-message="errorMessage"
/>
and the form validation is really not built-in, which is very speechless. It is recommended that you combine async-validator to join one, and it is not difficult
.
error-message can bind a string variable, remember to add a colon (: error-message= "yourText")
for example, enter an account and enter a password:
<van-row class="register-name">
<van-field
v-model="username"
clearable
label=""
icon="question"
placeholder="/"
:error-message="errorMessage.userInput"
/>
</van-row>
<van-row class="register-password">
<van-field
v-model="password"
type="password"
label=""
placeholder=""
:error-message="errorMessage.pwdInput"
/>
</van-row>
definition errorMessage: in data
errorMessage: { userInput:"", pwdInput:"", zipCode:"" },
Ps: I store all the information that needs a red prompt in an errorMessage object, which is convenient to change and add code.
is easy to use!
this.errorMessage.pwdInput = "password error" page response displays the prompt;
if you want to turn off the prompt, it's even easier.
Direct this.errorMessage.pwdInput = " assignment is empty.
for final verification, if I write too much, I will sum up a set of general regular sum verification methods, and encapsulate it by myself. Every time I use it, I will directly import . How happy I am! 2333
can your v-model be used?
van-card build has no way to v-for? Use the direct error report?
< van-field VMI model = "mobile" name= "mobile" placeholder= "Mobile": rules= "[{required: true, message: 'Please fill in Mobile phone'}, {pattern, message: 'Mobile number is not in the correct format'}]" / >
data: {pattern: / ^ 1d {10} /}