Element UI select 组件验证:改变时不检验内容的解决方法
<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>
<p>根据你提供的代码,可以看到你使用了<code>trigger: 'change'</code>来触发验证的条件。这意味着只有在<code>select</code>元素的值发生改变时,验证才会被触发。</p>
<p>如果你希望在其他事件(例如输入框失去焦点)时也触发验证,你可以将<code>trigger</code>的值设置为<code>['change', 'blur']</code>,这样无论是改变值还是失去焦点都会触发验证。</p>
<p>以下是修改后的代码示例:</p>
<pre><code class="language-html"><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>
</code></pre>
<p>希望这可以帮助到你!</p>
原文地址: https://www.cveoy.top/t/topic/p14r 著作权归作者所有。请勿转载和采集!