ant-design-vue/components/transfer/demo/search.vue
Cherry7 9be58078d2
Refactor(demo): change options to composition api (#6499)
* feat(demo): A-B

* feat(demo): update B-checkbox

* feat(demo): update CheckBox -DatePicker

* feat(demo): update DatePicker - Form

* feat(demo): update Form - List

* feat(demo): update  List-pagination

* feat(demo): update  List - skeleton

* feat(demo): update  skeleton - switch

* feat(demo): update  skeleton - switch

* feat(demo): update   switch - upload

* feat(demo): update  watermark

* fix(demo): del hashId
2023-04-28 14:08:21 +08:00

73 lines
1.4 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<docs>
---
order: 2
title:
zh-CN: 带搜索框
en-US: Search
---
## zh-CN
带搜索框的穿梭框可以自定义搜索函数
## en-US
Transfer with a search box.
</docs>
<template>
<a-transfer
v-model:target-keys="targetKeys"
:data-source="mockData"
show-search
:filter-option="filterOption"
:render="item => item.title"
@change="handleChange"
@search="handleSearch"
/>
</template>
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
interface MockData {
key: string;
title: string;
description: string;
chosen: boolean;
}
const mockData = ref<MockData[]>([]);
const targetKeys = ref<string[]>([]);
onMounted(() => {
getMock();
});
const getMock = () => {
const keys = [];
const mData = [];
for (let i = 0; i < 20; i++) {
const data = {
key: i.toString(),
title: `content${i + 1}`,
description: `description of content${i + 1}`,
chosen: Math.random() * 2 > 1,
};
if (data.chosen) {
keys.push(data.key);
}
mData.push(data);
}
mockData.value = mData;
targetKeys.value = keys;
};
const filterOption = (inputValue: string, option: MockData) => {
return option.description.indexOf(inputValue) > -1;
};
const handleChange = (keys: string[], direction: string, moveKeys: string[]) => {
console.log(keys, direction, moveKeys);
};
const handleSearch = (dir: string, value: string) => {
console.log('search:', dir, value);
};
</script>