1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <template> <el-select v-model="selectedValue" ref="mySelect" @change="handleChange"> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </template>
<script> export default { data() { return { selectedValue: '', options: [ { value: 'option1', label: '选项1' }, { value: 'option2', label: '选项2' }, { value: 'option3', label: '选项3' } ] } }, methods: { handleChange() { const selectedLabel = this.$refs.mySelect.selectedLabel console.log(selectedLabel) } } } </script>
|
在el-select组件上添加ref属性,然后在handleChange方法中通过this.$refs.mySelect获取到组件实例,然后通过selectedLabel属性获取到选中的label值。
需要注意的是,selectedLabel属性只有在el-select组件的multiple属性为false时才有效。如果multiple属性为true,则需要通过selected属性获取到选中的选项数组,然后遍历数组获取到每个选项的label值。
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!