【vue2】element两个select用同一个options。下拉框内容是互斥状态。一个多选一个单选。多选实现(全选,反选,清空)功能

前景提要:两个下拉框。第一个是多选。第二个是单选。如果选到了的value那另一个下拉框则不显示。
并且多选要实现(全选/反选/清空)功能
在这里插入图片描述
直接上代码

template

<div>
            Feature Select:
            <el-select
              v-model="featureSelectValue"
              multiple
              placeholder="请选择"
              @change="featureSelect"
              @remove-tag="featureRemoveTag"
              style="width: 400px"
              :popper-append-to-body="false"
            >
              <div class="select_up" style="margin-left: 20px">
                <el-button type="text" v-on:click="selectDevAll">
                  <i class="el-icon-circle-check" />
                  全选</el-button
                >
                <el-button type="text" v-on:click="removeDevTag">
                  <i class="el-icon-close" />
                  清空</el-button
                >
                <el-button type="text" v-on:click="selectDevReverse">
                  <i class="el-icon-copy-document" />
                  反选</el-button
                >
              </div>
              <el-option
                v-for="(item, index) in featureColumns"
                :key="index"
                :label="item.label"
                :value="item.prop"
              >
              </el-option>
            </el-select>
          </div>
          <div style="margin-top: 20px; margin-left: 16px">
            Taret Select:
            <el-select
              v-model="targetSelectValue"
              placeholder="请选择"
              @change="targetSelect"
              clearable
              :popper-append-to-body="false"
            >
              <el-option
                v-for="(item, index) in targetColumns"
                :key="index"
                :label="item.label"
                :value="item.prop"
              >
              </el-option>
            </el-select>
          </div>

script

data(){
	previewColumnData: [],//两个共用的所有options
   featureColumns: [],//多选框的下拉框options
   featureSelectValue: [],//多选框选中的值
   targetColumns: [],//单选框下拉框options
   targetSelectValue: [],//单选框选中的值
},
methods:{
	//互斥的方法
 	commonFun() {
      const allOption = this.previewColumnData;
      this.targetColumns = allOption.filter(
        (item) => !this.featureSelectValue.includes(item.label)
      );
    },
    //多选框选中的fun
    featureSelect(value) {
      this.commonFun();
    },
    //多选框单个移除的fun
    featureRemoveTag(value) {
      this.commonFun();
    },
    //单选框选择的fun
    targetSelect(value) {
      this.commonFun();
    },
  //清空操作
    removeDevTag() {
      this.featureSelectValue = [];
      this.commonFun();
    },
    //全选
    selectDevAll() {
      this.featureSelectValue = this.featureColumns.map((item) => item.label);
      this.commonFun();
    },
    //反选
    selectDevReverse() {
      this.featureSelectValue = this.featureColumns
        .filter((item) => !this.featureSelectValue.includes(item.label))
        .map((item) => item.label);
      this.commonFun();
    },
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值