vue Transfer 穿梭框

html 内联代码片

// An highlighted block
  <el-transfer
              style="text-align: left; display: inline-block"
              v-model="rolesle"
              :titles="['未继承角色', '已继承角色']"
              :button-texts="['到左边', '到右边']"
              :format="{
                noChecked: '${total}',
                hasChecked: '${checked}/${total}',
              }"
              @change="handleChange"
              :data="roleInherit"
              :props="{
                key: 'id',
                label: 'name',
              }"
            ></el-transfer>

数据


data(){
    return{
      value: [1, 2],//选中的数组id,处理数据是把选中的数据id,push到这个数组中
      bcalldata: [],
      leftvalue: [],
      rightvalue: [],
      datas: [
        {
          id: 1,
          name: '北京',
        },
        {
          id: 2,
          name: '上海',
        },
        {
          id: 3,
          name: '深广州圳',
        },
        {
          id: 4,
          name: '深圳',
        },
      ],
}

事件:此事件中value就是当前值,direction是代表方向:right-右边;left-左边,movedKeys是代表发生移动的数据 key 数组,保存数据需要向后台提交选中的id - movedKeys

// An highlighted block
handleChange(value, direction, movedKeys) {
      console.log(value, direction, movedKeys)
      if (direction === 'right') {
        movedKeys.forEach((key) => {
          let index = this.leftvalue.findIndex((item) => item === key)
          this.leftvalue.splice(index, 1)
        })
        movedKeys.forEach((key) => {
          this.rightvalue.push(key)
        })
      } else {
        movedKeys.forEach((key) => {
          let index = this.rightvalue.findIndex((item) => item === key)
          this.rightvalue.splice(index, 1)
        })
        movedKeys.forEach((key) => {
          this.leftvalue.push(key)
        })
      }
      console.log(this.leftvalue)
      console.log(this.rightvalue)
    },

参考:链接: link.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值