Vue+element Ui的el-select同时获取value和label的方法总结

1.通过ref的形式(推荐)

javascript 复制代码
<template>
  <div class="root">
    <el-select
      ref="optionRef"
      @change="handleChange"
      v-model="value"
      placeholder="请选择"
      style="width: 250px"
    >
      <el-option
        v-for="item in options"
        :key="item.id"
        :label="item.label"
        :value="item.value"
      >
      </el-option>
    </el-select>
    <el-button style="margin-left: 20px" @click="showoptions" type="primary" >查看</el-button >
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: "",
      options: [
        { id: 0, label: "苹果", value: "apple" },
        { id: 1, label: "香蕉", value: "banana" },
        { id: 2, label: "橙子", value: "orange" },
      ],
    };
  },
  methods: {
    showoptions() {
      console.log(
        this.$refs.optionRef.selected.value,
        this.$refs.optionRef.selected.label
      );
    },
    handleChange(){
      // change 改变后获取值,要在nextTick中。
      this.$nextTick(function () {
        this.$refs.optionRef.selected.value,
        this.$refs.optionRef.selected.label
      });
    }
  },
};
</script>

2.通过字符串拼接的形式(推荐)

javascript 复制代码
<template>
  <div class="root">
    <el-select ref="optionRef" @change="handleChange" v-model="value" placeholder="请选择" style="width: 250px">
      <el-option v-for="item in options" :key="item.id" :label="item.label" :value="item.value">
      </el-option>
    </el-select>
    <el-button style="margin-left: 20px" @click="showoptions" type="primary">查看</el-button>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        value: "",
        options: [
          { id: 0, label: "苹果", value: "apple" },
          { id: 1, label: "香蕉", value: "banana" },
          { id: 2, label: "橙子", value: "orange" },
        ],
      };
    },
    methods: {
      showoptions() {
        console.log(this.value);
        console.log("value=====", this.value.split("+")[0]);
        console.log("label=====", this.value.split("+")[1]);
      },
      handleChange() {
        // change 改变后获取值,要在nextTick中。
        this.$nextTick(function () {
          console.log(this.value);
          console.log("value=====", this.value.split("+")[0]);
          console.log("label=====", this.value.split("+")[1]);
        });
      }
    },
  };
</script>

3.通过遍历的形式(不推荐)

javascript 复制代码
<template>
  <div class="root">
    <el-select ref="optionRef" @change="handleChange" v-model="value" placeholder="请选择" style="width: 250px">
      <el-option v-for="item in options" :key="item.id" :label="item.label" :value="item.value">
      </el-option>
    </el-select>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        value: "",
        options: [
          { id: 0, label: "苹果", value: "apple" },
          { id: 1, label: "香蕉", value: "banana" },
          { id: 2, label: "橙子", value: "orange" },
        ],
      };
    },
    methods: {
    
      handleChange(v) {
        // change 改变后获取值,要在nextTick中。
        this.$nextTick(function () {
          let obj = this.options.find(item=>item.value==v)
          console.log("value=====", obj.value);
          console.log("label=====", obj.label);
        });
      }
    },
  };
</script>
相关推荐
默_笙16 分钟前
🚦 请三个 AI 考官给 RAG 打分:量化评估实战(下)
前端·javascript
阿坨19 分钟前
灵感闪存卡:一款 Tampermonkey用户脚本
javascript·tampermonkey
朝朝辞暮i2 小时前
C++ 第 25 课:getter / setter + this
java·javascript·c++
蜗牛互联网2 小时前
Python接入Gemini 3.8 Flash实现票据视觉抽取与规则校验
java·javascript·网络·人工智能·python
易朵朵3 小时前
CSS 格式化上下文
css·vue.js
xieter4 小时前
【技术精选】深入浅出现代前端渲染与性能优化实践指南 (2026-10-04)
前端·javascript
xieter4 小时前
【硬核实战】TypeScript Compiler API: Preserving Child Node Narrowing in Reusable Type Guards 🔧 (2026-10-03)
前端·javascript
xieter4 小时前
【硬核实战】React 19 useFormStatus Returning False? I Built a SubmitButton That Fixes It (2026-10-03)
前端·javascript
雪芽蓝域zzs5 小时前
第6节:远程搜索弹窗(remote 模式),弹窗滚动加载分页
vue.js·elementui
paopaokaka_luck5 小时前
非遗文物数字化小程序(AI非遗问答、ONNX图像识别、协同过滤推荐、ECharts数据分析、非遗知识浏览与互动、文创商城订单闭环、文化活动报名签到、社区交流)
javascript·spring boot·mysql·数据分析·echarts·mybatis