赞
踩
- <!-- :validate-on-rule-change="false" 是为了阻止更改rules时立即触发校验-->
- <el-form :model="form" ref="orderForm" :rules="formRules" :validate-on-rule-change="false">
- <el-form-item label="类型" prop="type">
- <el-radio-group v-model="form.type" @change="needCustNm">
- <el-radio-button value="1" label="采购备货"></el-radio-button>
- <el-radio-button value="2" label="业务备货"></el-radio-button>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="客户" prop="custNm">
- <el-input v-model="form.custNm" placeholder="请输入客户"></el-input>
- </el-form-item>
- </el-form>
-
-
- ......
- // 初始化设置
- const formRules = ref({
- type: [
- {
- required: true,
- message: '请选择类型',
- trigger: 'change',
- },
- ]
- });
-
- // 切换类型时
- function needCustNm(){
- if(form.value.type == '2'){
- formRules.value = {
- type: [
- {
- required: true,
- message: '请选择类型',
- trigger: 'change',
- },
- ],
- custNm:[
- {
- required: true,
- message: '请输入客户',
- trigger: 'change',
- },
- ]
- }
- }else{
- formRules.value = {
- type: [
- {
- required: true,
- message: '请选择类型',
- trigger: 'change',
- },
- ]
- }
- // 需要加nextTick,不然获取不到
- nextTick(()=>{
- // 清除校验效果
- proxy.$refs["orderForm"] && proxy.$refs["orderForm"].clearValidate()
- })
- }
- }
:validate-on-rule-change="false" 是为了阻止更改rules时立即触发校验
- nextTick(()=>{
- // 清除校验效果
- proxy.$refs["orderForm"] && proxy.$refs["orderForm"].clearValidate()
- })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。