Vue Element UI el-select 回显问题:v-model 值在无 label 属性时显示为空
Vue Element UI el-select 回显问题:v-model 值在无 label 属性时显示为空
在使用 Vue Element UI 的 el-select 组件时,如果在 el-option 中没有设置 label 属性,则 v-model 绑定的值无法被正确回显。这是因为 el-select 组件是根据 label 属性来显示选项文本和回显值的。
如果你没有设置 label 属性,可以考虑使用 value 属性来代替。例如:
<el-select v-model='selectedValue'>
<el-option v-for='item in options' :key='item.id' :value='item.id'>{{ item.name }}</el-option>
</el-select>
在这个例子中,我们将选项的 id 属性作为 value 绑定,而将选项的 name 属性作为显示文本。这样,在回显时,selectedValue 变量将会被正确设置为选项的 id 值。
原文地址: https://www.cveoy.top/t/topic/os7K 著作权归作者所有。请勿转载和采集!