Element ui 框架型
<el-select v-model="sketchID" autocomplete="off" @@change="setEmpty" id="sketchID2"> <el-option v-for="item in sketchOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option> </el-select>
setEmpty:function (data) { var _this = this console.log('data',data) let obj = {}; obj = this.sketchOptions.find((item)=>{//这里的sketchOptions就是上面遍历的数据源 return item.value === data;//筛选出匹配数据 }) console.log('obj.label',obj.label);
console.log('obj.value',obj.value);
},
sketchOptions: [{ value: '1', label: '安装位置不正确' }, { value: '2', label: '空置房' }],
原生型:
<select autocomplete="off" @change="setEmpty" id="sketchID"> <option v-for="item in sketchOptions" :key="item.value" :label="item.label" :value="item.value"> </option> </select>
setEmpty:function () { var _this = thisvar s = $("#sketchID").find("option:selected").text();
console.log(s.text())
console.log(s.value())
}