ワンクリックで
n-dynamic-tags
A component for dynamically adding and removing tags with customizable input and trigger elements
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
A component for dynamically adding and removing tags with customizable input and trigger elements
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
FormCreate(运行态渲染器)使用与扩展助手:围绕 rule/option/api 的编写、调试与迁移,覆盖 v-model:api / create 获取实例、字段联动(control/computed)、校验(validate)、远程 fetch、事件注入(inject/formCreateInject)、序列化保存回显(parseJson/toJson)以及多 UI 栈(Antd/Naive/Vant/Arco/TDesign/Element)props/on 差异。权威口径以 `AGENTS.md` 与 `references/types.md` 为准;涉及设计器 ref/config 请用 **FcDesigner使用助手**,涉及安装与包名请选择 **FormCreate安装助手**。
Naive UI Skills Library - A comprehensive skill library for AI agents to understand and utilize Naive UI components. Invoke when user needs to work with Naive UI components, theming, i18n, dark mode, or design specifications.
Work on the Vane server app in apps/server. Use when adding, modifying, reviewing, or debugging server routes, serve-layer data access, middlewares, auth, logging, uploads, database-backed features, or Express response behavior in this repository.
Affix component that makes content stick to fixed places when scrolling. Invoke when user needs to implement sticky positioning or fixed elements in Naive UI.
Alert component for displaying important messages and notifications. Invoke when user needs to show contextual feedback messages with different types and styles in Naive UI.
Anchor component for navigation and table of contents. Invoke when user needs to implement anchor navigation, table of contents, or scroll-based navigation highlighting in Naive UI.
| name | n-dynamic-tags |
| description | A component for dynamically adding and removing tags with customizable input and trigger elements |
| author | jiaiyan |
| version | 1.0.0 |
The n-dynamic-tags component allows users to create and manage tags dynamically. Tags can be added by typing and pressing Enter, and removed by clicking the close button. It supports custom rendering and input elements.
Use n-dynamic-tags when you need to:
<template>
<n-dynamic-tags v-model:value="tags" />
</template>
<script setup>
import { ref } from 'vue';
const tags = ref(['Tag 1', 'Tag 2']);
</script>
<template>
<n-dynamic-tags v-model:value="tags" :max="3" />
</template>
<template>
<n-space vertical>
<n-dynamic-tags v-model:value="tags" type="primary" />
<n-dynamic-tags v-model:value="tags" type="info" />
<n-dynamic-tags v-model:value="tags" type="success" />
<n-dynamic-tags v-model:value="tags" type="warning" />
<n-dynamic-tags v-model:value="tags" type="error" />
<n-dynamic-tags v-model:value="tags" round />
</n-space>
</template>
| Name | Type | Default | Description |
|---|---|---|---|
value / v-model:value | string[] | DynamicTagsOption[] | undefined | Value if manually set. |
default-value | string[] | [] | Default value. |
disabled | boolean | false | Whether the tag is disabled. |
closable | boolean | true | Whether the tag is closable. |
max | number | undefined | Maximum number of tags. |
size | 'small' | 'medium' | 'large' | 'medium' | Size of the tag. |
type | 'default' | 'primary' | 'info' | 'success' | 'warning' | 'error' | 'default' | Type of the tag. |
round | boolean | false | Whether the tag has rounded corners. |
color | { color?: string, borderColor?: string, textColor?: string } | undefined | Color of the tag. Overrides color set by type. |
render-tag | (tag: string | DynamicTagsOption, index: number) => VNodeChild | undefined | Custom render tag function. |
input-props | InputProps | undefined | Props of internal n-input. |
input-style | string | Object | undefined | Customize the style of the input. |
input-class | string | undefined | Customize the class of the input. |
tag-style | string | Object | undefined | Customize the style of the tag. |
tag-class | string | undefined | Customize the class of the tag. |
interface DynamicTagsOption {
label: string;
value: string;
}
| Name | Parameters | Description |
|---|---|---|
update:value | (value: string[] | DynamicTagsOption[]) => void | Callback when value changes. |
create | (label: string) => string | DynamicTagsOption | Create derived value from input. |
| Name | Parameters | Description |
|---|---|---|
input | { submit: (value: any) => void, deactivate: () => void } | Custom element to replace the regular input. |
trigger | { activate: () => void, disabled: boolean } | Element that triggers the tag to switch to input. |
<template>
<n-dynamic-tags v-model:value="tags">
<template #input="{ submit, deactivate }">
<n-auto-complete
ref="autoCompleteInstRef"
v-model:value="inputValue"
size="small"
:options="options"
placeholder="Email"
:clear-after-select="true"
@select="submit($event)"
@blur="deactivate"
/>
</template>
</n-dynamic-tags>
</template>
<script setup>
import { ref } from 'vue';
const tags = ref([]);
const inputValue = ref('');
const options = ref([
{ label: 'user1@example.com', value: 'user1@example.com' },
{ label: 'user2@example.com', value: 'user2@example.com' },
]);
</script>
<template>
<n-dynamic-tags v-model:value="tags" :render-tag="renderTag" />
</template>
<script setup>
import { h } from 'vue';
import { NTag } from 'naive-ui';
const tags = ref(['Apple', 'Banana', 'Orange']);
const renderTag = (tag, index) => {
return h(
NTag,
{
type: 'primary',
bordered: false,
closable: true,
onClose: () => tags.value.splice(index, 1),
},
{ default: () => tag },
);
};
</script>
<template>
<n-dynamic-tags v-model:value="value" @create="onCreate" />
<pre>{{ JSON.stringify(value, null, 2) }}</pre>
</template>
<script setup>
import { ref } from 'vue';
const value = ref([
{ label: 'Vue', value: 'vue' },
{ label: 'React', value: 'react' },
]);
const onCreate = label => {
return {
label,
value: label.toLowerCase().replace(/\s+/g, '-'),
};
};
</script>
<template>
<n-dynamic-tags @create="handleCreate" />
</template>
<script setup>
const handleCreate = label => {
if (label.length < 2) {
return label;
}
return label.toUpperCase();
};
</script>
<template>
<n-form :model="model" :rules="rules">
<n-form-item path="tags" :show-label="false">
<n-dynamic-tags v-model:value="model.tags" />
</n-form-item>
</n-form>
</template>
<script setup>
import { ref } from 'vue';
const model = ref({
tags: [],
});
const rules = {
tags: {
type: 'array',
required: true,
message: 'At least one tag is required',
},
};
</script>
Use max to limit tag count: Set a maximum number of tags to prevent excessive input.
Customize input with slots: Use the input slot for autocomplete or other input components.
Use on-create for value transformation: Transform user input before adding as a tag (e.g., lowercase, trim).
Use object format for complex data: When tags need both display label and value, use DynamicTagsOption format.
Combine with form validation: Wrap in n-form-item for validation support.