前言:
由于vue中form表单的检验是否通过是取决于form表单中对应的属性是否有值,有值则无提示信息,无值则有提示信息。
<el-form :model="form" :rules="rules">
<el-form-item label="地区" prop="address">
<el-cascader
:props="props"
@change="handleCheckData"
></el-cascader>
</el-form-item>
</el-form>
data(){
return {
from: {
address: ""
},
const rules = {
address: [
{ required: true, message: "所属地区不能为空", trigger: "change" },
],
}
}
}
handleCheckData(val) {
//关键代码,给form表单中的address添加校验
this.form.address = val.join(',');
}