el-form-item label=类型 prop=typeid select v-model=ruleFormtypeid style=margin-bottom 10px; option v-for=item in allTypes key=itemid value=itemid itemname option se
根据你提供的代码,可以看到你使用了trigger: 'change'来触发验证的条件。这意味着只有在select元素的值发生改变时,验证才会被触发。
如果你希望在其他事件(例如输入框失去焦点)时也触发验证,你可以将trigger的值设置为['change', 'blur'],这样无论是改变值还是失去焦点都会触发验证。
以下是修改后的代码示例:
<el-form-item label="类型" prop="typeid">
<select v-model="ruleForm.typeid" style="margin-bottom: 10px;">
<option v-for="item in allTypes" :key="item.id" :value="item.id">
{{ item.name }}
</option>
</select>
</el-form-item>
<script>
export default {
data() {
return {
ruleForm: {
typeid: null
},
allTypes: [
{ id: 1, name: '类型1' },
{ id: 2, name: '类型2' },
{ id: 3, name: '类型3' }
]
};
}
};
</script>
<script>
export default {
data() {
return {
ruleForm: {
typeid: null
},
allTypes: [
{ id: 1, name: '类型1' },
{ id: 2, name: '类型2' },
{ id: 3, name: '类型3' }
]
};
}
};
</script>
<script>
export default {
data() {
return {
ruleForm: {
typeid: null
},
allTypes: [
{ id: 1, name: '类型1' },
{ id: 2, name: '类型2' },
{ id: 3, name: '类型3' }
]
};
}
};
</script>
希望这可以帮助到你
原文地址: http://www.cveoy.top/t/topic/iZ9x 著作权归作者所有。请勿转载和采集!