el-dropdown下拉框点击事件,获取点击选项的值和label

 command事件

<el-dropdown @command="handleCommand">
  <span>
    经销料种<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
  <el-dropdown-menu slot="dropdown">
    <el-dropdown-item
      v-for="item in distributionVariety"
      :key="item.lineCode"
      :command="item.lineCode"
    >
      {
   
   { item.lineName }}
   </el-dropdown-item>
 </el-dropdown-menu>
</el-dropdown>

用数组的find方法找到点击选项的lineName值 

handleCommand(command) {
      const item = this.distributionVariety.find((item) => item.lineCode === command);
      console.log(`点击了${item.lineName}`);
      if (item.lineCode) {
        this.selectedDistriVariety.push(item)
        console.log(this.selectedDistriVariety);
      }
    },

猜你喜欢

转载自blog.csdn.net/Dolores_zsq/article/details/130585319
今日推荐