ant-design-vue/components/select/demo/responsive.vue

87 lines
2.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<docs>
---
order: 24
title:
zh-CN: 最多显示多少个选项及选项最大长度
en-US: set maxTagCount or maxTagTextLength
---
## zh-CN
设置一个数字超过后自动折叠
maxTagCount 也可以设置成响应式但响应式对性能有所消耗不推荐在大表单场景下使用
## en-US
Set a number and automatically fold after exceeding.
`maxTagCount` can also be set to responsive, but responsive consumes performance and is not recommended for use in large-form scenarios.
</docs>
<template>
<a-space direction="vertical" style="width: 100%">
<a-space>
<a-button type="primary" @click="maxTagCount++">maxTagCount++</a-button>
<a-button type="primary" @click="maxTagCount--">maxTagCount--</a-button>
</a-space>
<h2>maxTagCount: {{ maxTagCount }}</h2>
<a-select
v-model:value="value"
mode="multiple"
style="width: 100%"
placeholder="Select Item..."
:max-tag-count="maxTagCount"
:options="options"
></a-select>
<h2>maxTagCount: responsive</h2>
<a-select
v-model:value="value"
mode="multiple"
style="width: 100%"
placeholder="Select Item..."
max-tag-count="responsive"
:options="options"
></a-select>
<a-space>
<a-button type="primary" @click="maxTagTextLength++">maxTagTextLength++</a-button>
<a-button type="primary" @click="maxTagTextLength--">maxTagTextLength--</a-button>
</a-space>
<h2>maxTagTextLength: {{ maxTagTextLength }}</h2>
<a-select
v-model:value="value"
mode="multiple"
style="width: 100%"
placeholder="Select Item..."
:max-tag-text-length="maxTagTextLength"
:options="options"
></a-select>
</a-space>
</template>
<script lang="ts">
import type { SelectProps } from 'ant-design-vue';
import { defineComponent, ref } from 'vue';
export default defineComponent({
setup() {
const options = ref<SelectProps['options']>([]);
for (let i = 10; i < 36; i++) {
const value = i.toString(36) + i;
options.value.push({
label: `Long Label: ${value}`,
value,
});
}
const maxTagCount = ref(2);
const maxTagTextLength = ref(10);
return {
value: ref(['a10', 'c12', 'h17', 'j19', 'k20']),
options,
maxTagCount,
maxTagTextLength,
};
},
});
</script>