我有一個表格
<form>
<div class="form-group">
<label for="email">Email address</label>
<input v-model="email" for="email" type="email" class="form-control" placeholder="Enter email" required>
</div>
<div class="form-group">
<label for="name">Name</label>
<input v-model="name" for="name" type="text" class="form-control" placeholder="Name" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input v-model="password" type="password" class="form-control" for="password" placeholder="Password" required>
</div>
<div class="form-group">
<label for="Confirm">Confirm Password</label>
<input v-model="confirmPassword" type="password" class="form-control" for="Confirm" placeholder="Confirm Password" required>
</div>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1" required>
<label class="form-check-label" for="exampleCheck1">I agree to the terms and conditions</label>
</div>
<button v-on:click="Submit" type="submit" class="btn btn-primary">Submit</button>
data(){
return{
email: undefined,
password: undefined,
confirmPassword: undefined,
name: undefined
}
}
目前是這樣判斷
methods:{
Submit(){
var allFill = this.email !== undefined && this.password !== undefined && this.confirmPassword !== undefined && this.name !== undefined;
}
}
請問是否有優雅的方式,能判斷所有欄位都被填寫了?
可以用 VeeValidate 設定 rules = 必須填寫
, 變相達到要求。
如同官網範例 :
<validation-provider rules="required" v-slot="{ errors }">
<input v-model="value" name="myinput" type="text" />
<span>{{ errors[0] }}</span>
</validation-provider>