Vue3双向绑定选择框select动态选项 官网
有时选择框的选项需动态生成,可借助v-for指令遍历数组生成选项。 template select v-model="selected" option v-for="option in options" :key="option" :value="option" {{ option }} /option /select p你选的是: {{ selected }}/p/templatescript setupimport { ref } from 'vue';const options = ref(['苹果', '香蕉', '橙子']);const selected = ref('苹果'); // 初始值// 运行结果:页面显示选择框,选项为苹果、香蕉、橙子,默认选中苹果,下方显示选择的内容/script 用v-for生成选项时,要给每个选项加上:key,以提升渲染性能。