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;
}
相关推荐
RFCEO8 分钟前
前端编程 课程十三、:CSS核心基础1:CSS选择器
前端·css·css基础选择器详细教程·css类选择器使用方法·css类选择器命名规范·css后代选择器·精准选中嵌套元素
烬头882132 分钟前
React Native鸿蒙跨平台采用了函数式组件的形式,通过 props 接收分类数据,使用 TouchableOpacity实现了点击交互效果
javascript·react native·react.js·ecmascript·交互·harmonyos
Amumu1213833 分钟前
Vuex介绍
前端·javascript·vue.js
We་ct34 分钟前
LeetCode 54. 螺旋矩阵:两种解法吃透顺时针遍历逻辑
前端·算法·leetcode·矩阵·typescript
2601_949809591 小时前
flutter_for_openharmony家庭相册app实战+相册详情实现
javascript·flutter·ajax
qq_177767371 小时前
React Native鸿蒙跨平台通过Animated.Value.interpolate实现滚动距离到动画属性的映射
javascript·react native·react.js·harmonyos
2601_949833391 小时前
flutter_for_openharmony口腔护理app实战+饮食记录实现
android·javascript·flutter
2601_949480061 小时前
【无标题】
开发语言·前端·javascript
css趣多多1 小时前
Vue过滤器
前端·javascript·vue.js
理人综艺好会2 小时前
Web学习之用户认证
前端·学习