(vue)el-select选择框加全选/清空/反选


在这里插入图片描述


<el-form-item label="批次">
	<el-select
	  v-model="formInline.processBatch"
	  multiple
	  collapse-tags
	  filterable
	  placeholder="请选择"
	  style="width: 250px"
	  no-data-text="请先选择企业、日期、工序"
	  @visible-change="piciSearch" //下拉打开/关闭时 事件
	>
	  <div class="select_up">
	    <el-button type="text" @click="selectAll">
	      <i class="el-icon-document-checked" />
	      全选</el-button>
	    <el-button type="text" @click="removeTag">
	      <i class="el-icon-document-delete" />
	      清空</el-button>
	    <el-button type="text" @click="selectReverse">
	      <i class="el-icon-document-copy" />
	      反选</el-button>
	  </div>
	  <div class="select_list">
	    <el-option
	      v-for="item in piciOptions"
	      :key="item.batchNum"
	      :label="item.batchNum"
	      :value="item.batchNum"
	    />
	  </div>
	</el-select>
</el-form-item>

js


// 清空操作
removeTag() {
  this.formInline.processBatch = []
},
// 全选操作
selectAll(val) {
  val = []
  this.piciOptions.map(item => {
    val.push(item.batchNum)
  })
  this.formInline.processBatch = val
},
// 反选操作
selectReverse(val) {
  val = []
  this.piciOptions.map(item => {
    const index = this.formInline.processBatch.indexOf(item.batchNum)
    // 判断现有选中数据是否包含如果不包含则进行反选数据
    if (index !== -1) {
      // formInline.processBatch.splice(index, 1)
    } else {
      val.push(item.batchNum)
    }
  })
  this.formInline.processBatch = val
},

解决参考

1.全选/清空/反选

在这里插入图片描述
2.全选/反选

在这里插入图片描述

GitHub 加速计划 / vu / vue
88
16
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:7 个月前 )
9e887079 [skip ci] 5 个月前
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 9 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐