VUE 带有搜索功能的穿梭框(简单demo)

一、template/

组件代码

c 复制代码
  <el-dialog :title="title" :visible.sync="dialogVisible" width="60%" :before-close="handleClose" class="custom-dialog-line" >
    <div style="text-align: center ; width: 100%; height: 450px;">
      <el-transfer
        filterable
        :filter-method="filterMethod"
        filter-placeholder="请输入搜索名称"
        v-model="valueList"
        @change="handleChange"
        :data="lineData">
        <el-button class="transfer-footer" slot="right-footer" size="small" @click="conformsLine">确定</el-button>
      </el-transfer>
    </div>
  </el-dialog>
c 复制代码
data(){
    return {
      lineData:[],
      dialogVisible: false,
      title: '申请审批单-变更',
      valueList: [],
      filterMethod(query, item) {
        return item.cityLine.indexOf(query) > -1;
      },
      cities: [], 
      cityLine: [], 
    }
  },

穿梭框数据可定义在前端也可由后端接口获取,以下示例为后端接口获取

cities: [],

cityLine: [],

c 复制代码
searchStationInfo(){
  this.lineData = [];
  let param = {lineName: this.lineName} // 过滤条件
  queryStation(param).then(res=>{
    if(res.code === '200'){
      this.cities = res.data.nameList;
      this.cityLine = res.data.lineList;
      this.cities.forEach((city, index) => {
        this.lineData.push({
          label: city,
          key: index,
          cityLine: this.cityLine[index]
        });
      });
    }
  })
},
handleChange(value, direction, movedKeys) {
// 此处可处理被刷选的数据逻辑。
},
handleClose(){
  this.$emit("close", false);
},

补充组件样式:样式示例,可自行调整

c 复制代码
/deep/ .el-transfer-panel {
    border: 1px solid #EBEEF5;
    border-radius: 4px;
    overflow: hidden;
    background: #FFF;
    display: inline-block;
    vertical-align: middle;
    width: 372px;
    max-height: 100%;
    box-sizing: border-box;
    position: relative;
}
/deep/ .el-transfer-panel__list.is-filterable {
    width: 90%;
    height: 202px;
    padding-top: 0;
}
/deep/ .el-transfer-panel__item.el-checkbox .el-checkbox__label {
    width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    box-sizing: border-box;
    padding-left: 24px;
    line-height: 30px;
}
/deep/ .el-checkbox {
    color: #606266;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    margin-right: 30px;
    width: 300px;
}
/deep/ .el-transfer-panel__item.el-checkbox .el-checkbox__label {
    width: 315px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
    box-sizing: border-box;
    padding-left: 24px;
    line-height: 30px;
}
/deep/ .el-checkbox-group {
  text-align: left;
}
 
 
/deep/ .el-checkbox {
  margin-left: 15px;
  margin-right: 25px;
  width: 240px;
  padding-left: 0px;
  text-align: left;  //这个很关键,否则每一行都是居中状态
}
/deep/ .el-transfer-panel__list.is-filterable {
    width: 90%;
    height: 249px;
    padding-top: 0;
}
/deep/  .el-transfer-panel__body{
    height: 350px;
}
相关推荐
顾安r4 小时前
11.8 脚本网页 星际逃生
c语言·前端·javascript·flask
Hello.Reader4 小时前
Data Sink定义、参数与可落地示例
java·前端·网络
im_AMBER5 小时前
React 17
前端·javascript·笔记·学习·react.js·前端框架
一雨方知深秋5 小时前
2.fs模块对计算机硬盘进行读写操作(Promise进行封装)
javascript·node.js·promise·v8·cpython
谷歌开发者6 小时前
Web 开发指向标 | Chrome 开发者工具学习资源 (六)
前端·chrome·学习
一晌小贪欢6 小时前
【Html模板】电商运营可视化大屏模板 Excel存储 + 一键导出(已上线-可预览)
前端·数据分析·html·excel·数据看板·电商大屏·大屏看板
发现你走远了6 小时前
连接模拟器网页进行h5的调试(使用Chrome远程调试(推荐)) 保姆级图文
前端·chrome
街尾杂货店&7 小时前
css - 实现三角形 div 容器,用css画一个三角形(提供示例源码)简单粗暴几行代码搞定!
前端·css
顺凡7 小时前
删一个却少俩:Antd Tag 多节点同时消失的原因
前端·javascript·面试
小白路过7 小时前
CSS transform矩阵变换全面解析
前端·css·矩阵