el-option选项内容是用v-for从数组循环读取的值,比如说我想设置第一个option为默认选中,或者最后一个为选中,该怎么写呢,谢谢大家了。
el-option选项内容是用v-for从数组循环读取的值,比如说我想设置第一个option为默认选中,或者最后一个为选中,该怎么写呢,谢谢大家了。
直接修改 select
组件的绑定值就行了。
比如说
<template>
<el-select v-mode="value">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
<el-select>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
interface ListItem {
value: string
label: string
}
const options = ref<ListItem[]>([])
const value = ref<string[]>([])
const remoteMethod = (query: string) => {
if (query) {
fetch(url,params).then(res => {
options.value = res.data
loading.value = res.data[0].value
})
} else {
options.value = []
}
}
</script>
3 回答3.3k 阅读✓ 已解决
4 回答1.9k 阅读✓ 已解决
4 回答3.4k 阅读
1 回答2.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
2 回答2.3k 阅读✓ 已解决
1 回答2.9k 阅读✓ 已解决
1 回答4k 阅读✓ 已解决
3 回答3.7k 阅读
309 阅读
1 回答4.8k 阅读✓ 已解决
1 回答1.8k 阅读
将绑定的value赋值v-model变量