vue +el+select 下拉框选择全部多选

vue +el+select 下拉框选择全部多选_第1张图片

1.html

   
        
          
          
        
      

2.script

  data() {
    return {
      form: { station_ids: "" },
      stationOptions: [
        { short_name: "出租车", station_id: "1" },
        { short_name: "出租", station_id: "2" },
        { short_name: "出", station_id: "3" },
        { short_name: "出租车", station_id: "4" },
      ],
      allReasonFlag: false,
    };
  },

    // 下拉框全选
    getReason(data, arr) {
      let allReasonFlag=false;
      if (allReasonFlag) {
        allReasonFlag = false;
        if (data.indexOf("all_dropdown_data") > -1) {
          this.form.station_ids = data.filter(res => res !== "all_dropdown_data");
        } else {
          this.form.station_ids = [];
        }
      } else {
        if (data.indexOf("all_dropdown_data") > -1) {
          this.form.station_ids = ["all_dropdown_data", ...arr.map(res => res.station_id)];
          allReasonFlag = true;
        } else {
          if (data.length === arr.length) {
            this.form.station_ids = ["all_dropdown_data", ...arr.map(res => res.station_id)];
            allReasonFlag = true;
          } else {
            this.form.station_ids = data;
          }
        }
      }
    }

你可能感兴趣的:(vue.js,前端,javascript)