elementUI的el-select選擇器同時返回選中項的value和label值

      <el-select v-model="ruleForm.category" @change="selectedCag" placeholder="請選擇項目類別">
          <el-option
          v-for="item in ClaOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
    methods: {
      selectedCag(vId){
        console.log(vId)
        let obj = {};
         obj = this.ClaOptions.find((item)=>{  //這裏的ClaOptions就是上面遍歷的數據源
             return item.value === vId;  //篩選出匹配數據,這裏的value是你遍歷數組每一項的value,如果沒有對後臺返回的數據做處理,一般爲id
         });
      console.log(obj.label);//  這裏的label就是對應label的
      this.addCagLabel = obj.label  //打印出來的obj.label就是想要的label值

      },   
   }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章