el-dropdown ドロップダウン ボックスのクリック イベント、クリックされたオプションの値とラベルを取得します

 コマンドイベント

<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