Galan小屋

welcome my blog

如何获取select组件的label值attr值

By galan99

发表于 2018-02-08

获取select选中的label


<template>
  <el-select v-model="value" placeholder="请选择" @change="changeValue">
    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
    </el-option>
  </el-select>
</template>

data:function(){
    return {
        options: [{
          value: '选项1',
          label: '黄金糕',
          id:'1',
        }, {
          value: '选项2',
          label: '双皮奶',
          id:'2',
        }, {
          value: '选项3',
          label: '蚵仔煎',
          id:'3',
        }, {
          value: '选项4',
          label: '龙须面',
          id:'4',
        }, {
          value: '选项5',
          label: '北京烤鸭',
          id:'5',
        }],
        value: ''
      }
    }
},
methods:{
    changeValue(val) {
        console.log(val);
        let obj = {};
        obj = this.options.find((item)=>{
            return item.value === val;
        });
        console.log(obj.label);
        console.log(obj.id);
    }
}