element-ui 之 select 获取key和label
作者:互联网
element-ui 之 select 获取key和label
element 获取下拉框的key和label, ---------个人理解: 这东西做的官方做的思考不全
01)使用循环
02) 使用 proxy.$refs 获取
<template> <div> <h3>下拉框 获取key和label</h3> <p> const {proxy} = getCurrentInstance(); </p> <el-select v-model="feiVal" ref="feiRefs" @change="handleChange"> <el-option v-for="item in [{value: 'da', label: '大'},{value: 'fei', label: '飞'}]" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </div> </template> <script setup> import {ref, getCurrentInstance, nextTick} from "vue"; const {proxy} = getCurrentInstance(); const feiRefs = ref(); const feiVal = ref(undefined); const handleChange = (val) => { console.log("下标值__",val); // 01) 使用循环遍历 // 02) 使用 proxy.$refs 获取 nextTick(()=>{ console.log("获取key和label",proxy.$refs.feiRefs.selected); console.log("获取label",proxy.$refs.feiRefs.selectedLabel); }) } </script>
标签:const,refs,label,获取,ui,proxy,key 来源: https://www.cnblogs.com/dafei4/p/16521162.html