優化:確定secondRules的數據在secondFlag改變之前進行賦值 可以用$nextTick來執行,不用setTimeOut
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.動態改變rules的值不起效果,所以看了別人的博客改了一下用computed監聽才起效果
<el-form ref="ruleForm" label-width="100px" :rules="currentRules" :model="ruleForm" class = "queryForm form_input">
</el-form>
computed: {
currentRules:function(){
console.log(this.secondFlag);
if(this.secondFlag){ //是否改變rules的判斷參數
return this.secondRules;
}else{
return this.rules;
}
},
},
因為我的第二個rules不是初始化的 是動態的數據,所以要先確定secondRules的數據在secondFlag改變之前進行賦值,所以我用了setTimeout處理。