vue el-selse回显v-model值问题当回显时el-option下没有当前v-model的值显这时候值显示数字如何不让它显示
如果在<el-option>下没有当前v-model的值时,你可以使用v-if或者v-show来判断是否显示该<el-option>。以下是一个示例代码:
<el-select v-model="selectedValue">
<el-option v-for="item in options" :key="item.value" :value="item.value" v-if="item.value !== selectedValue">
{{ item.label }}
</el-option>
</el-select>
在上面的代码中,我们使用了v-if="item.value !== selectedValue"来判断是否显示<el-option>。如果item.value不等于当前的selectedValue,则显示该选项。
另外,你也可以使用计算属性来过滤掉不需要显示的选项。以下是一个使用计算属性的示例代码:
<template>
<el-select v-model="selectedValue">
<el-option v-for="item in filteredOptions" :key="item.value" :value="item.value">
{{ item.label }}
</el-option>
</el-select>
</template>
<script>
export default {
data() {
return {
selectedValue: '',
options: [
{ label: 'Option 1', value: '1' },
{ label: 'Option 2', value: '2' },
{ label: 'Option 3', value: '3' }
]
};
},
computed: {
filteredOptions() {
return this.options.filter(item => item.value !== this.selectedValue);
}
}
};
</script>
在上面的代码中,我们使用了一个计算属性filteredOptions来过滤掉不需要显示的选项。在模板中,我们只需要循环渲染filteredOptions即可。这样就可以避免不需要显示的选项显示出来
原文地址: https://www.cveoy.top/t/topic/hYQD 著作权归作者所有。请勿转载和采集!