vue el-form多规则rules验证

【vue el-form多规则rules验证】rules使用计算属性返回:
computed中:

computed: { rules: function() { if (this.form.itemType) { return this.rules1 } else { return this.rules2 } } }

data中:
data() { return { rules1: { accno: [{ required: true, message: '不能为空', trigger: 'blur' }], accname: [{ required: true, message: '不能为空', trigger: 'blur' }], otp: [ { required: true, message: '不能为空', trigger: 'blur' }], username: [{ required: true, message: '不能为空', trigger: 'change' }] }, rules2: { pay_type: [{ required: true, message: '不能为空', trigger: 'change' }] }, } },

如果是rules1和rules2中都有的,可以两边都写,通过required:true和required:false来控制提示。

    推荐阅读