Skip to content

Transfer 穿梭框

双栏穿梭选择框,常用于将多个项目从一个列表转移到另一个列表。

基础用法

0 / 13
0 / 2
选中值: [ 1, 4 ]
vue
<template>
  <x-transfer v-model="value" :data="data" />
</template>

<script setup>
import { ref } from 'vue'

const value = ref([1, 4])

const data = ref([
  { key: 1, label: '选项 1' },
  { key: 2, label: '选项 2' },
  { key: 3, label: '选项 3', disabled: true },
  { key: 4, label: '选项 4' }
])
</script>

可搜索

设置 filterable 开启搜索功能。

0 / 15
0 / 0
暂无数据
vue
<template>
  <x-transfer
    v-model="value"
    :data="data"
    filterable
    filter-placeholder="请输入搜索内容"
  />
</template>

自定义搜索

使用 filter-method 自定义搜索逻辑。

0 / 15
0 / 0
暂无数据
vue
<template>
  <x-transfer
    v-model="value"
    :data="data"
    filterable
    :filter-method="filterMethod"
  />
</template>

<script setup>
const filterMethod = (query, item) => {
  return item.label.includes(query)
}
</script>

自定义标题和按钮

通过 titlesbutton-texts 自定义标题和按钮文本。

0 / 13
0 / 2
vue
<template>
  <x-transfer
    v-model="value"
    :data="data"
    :titles="['源列表', '目标列表']"
    :button-texts="['移除', '添加']"
  />
</template>

自定义数据字段

使用 props 属性自定义数据字段映射。

0 / 5
0 / 0
暂无数据
vue
<template>
  <x-transfer
    v-model="value"
    :data="data"
    :props="{
      key: 'id',
      label: 'name',
      disabled: 'locked'
    }"
  />
</template>

<script setup>
const value = ref([])

const data = ref([
  { id: 1, name: '选项 1', locked: false },
  { id: 2, name: '选项 2', locked: true },
  { id: 3, name: '选项 3', locked: false }
])
</script>

API

Props

属性说明类型默认值
modelValue目标列表的 key 数组(string | number)[][]
data数据源TransferOption[][]
titles自定义标题[string, string]['列表1', '列表2']
buttonTexts自定义按钮文本[string, string]['', '']
filterable是否可搜索booleanfalse
filterPlaceholder搜索框占位符string'请输入搜索内容'
filterMethod自定义搜索方法(query: string, option: TransferOption) => boolean
targetOrder目标列表排序方式'original' | 'push' | 'unshift''original'
props数据字段映射object

TransferOption 数据结构

字段说明类型默认值
key选项唯一标识string | number
label选项标签string
disabled是否禁用booleanfalse

Events

事件名说明回调参数
update:modelValue值变化时触发(value: (string | number)[])
change值变化时触发(value: (string | number)[], direction: 'left' | 'right', movedKeys: (string | number)[])
left-check-change左侧选中项变化时触发(checkedKeys: (string | number)[])
right-check-change右侧选中项变化时触发(checkedKeys: (string | number)[])

Methods

方法名说明参数
clearQuery清除搜索框内容(direction: 'left' | 'right')

Slots

插槽名说明
left-empty左侧空状态内容
right-empty右侧空状态内容

基于 MIT 许可发布