选择一个或以上的选项后,点击对应的方向键,可以把选中的选项移动到另一栏。其中,左边一栏为 source,
右边一栏为 target,API 的设计也反映了这两个概念。
<Transfer
:targetKeys="targetKeys" //穿梭到达目标
:data-source="mockData" //数据源 模板数据
:titles="['未添加', '已添加']"
:filter-option="filterOption"
:render="(item) => item.title" //每行数据渲染函数,该函数的入参为 dataSource 中的项,返回值为 ReactElement。
或者返回一个普通对象,其中 label 字段为 ReactElement,value 字段为 title
:list-style="{
width: '600px',
height: '400px',
}"
showSearch //是否显示搜索框
@change="handleChange"
@search="handleSearch"
/>
const targetKeys = ref([]);//定义为响应式
const mockData = ref([]);//调用API
//选项在两栏之间转移时的回调函数
const handleChange = (keys, direction, moveKeys) => {
keys -》组件当前已选 direction-》穿梭方向 moveKeys-》
console.log(keys, direction, moveKeys);
targetKeys.value = keys; //穿梭目标
// await api() //调用API
returnKeys = keys;
};