上一篇实际运行会出现点击按钮切换后自动验证的问题,影响用户体验。
重新梳理了代码:
表单
<template>
<el-form :model="form" ref="ref">
<el-form-item prop="a" :rules="aRules">
<el-input v-model="form.data1"></el-input>
</el-form-item>
<el-form-item prop="b" :rules="bRules">
<el-input v-model="form.data2"></el-input>
</el-form-item>
<el-form-item>
<el-button @click="submit">提交</el-button>
</el-form-item>
</el-form>
</template>
脚本
<script>
export default {
data () {
return {
// 判断条件
condition: false,
// 表单数据
form: {
data1: '',
data2: ''
},
aRules: {},
bRules: {}
}
},
created() {
this.init();
},
watch: {
condition(val) {
if (val) {
this.aRules = [