组件
动态输入 Dynamic Input
DynamicInput:动态输入列表。每行一个 Input,带一个低调的移除按钮,末尾提供添加行。列表受控:每次编辑都会发出新的数组,父级数组是唯一数据源。删除不会少于 `min`,添加不会超过 `max`,且组始终保留一行;否则清空后的录入列表会让使用者无处输入。
#基础用法
values: ["[email protected]",""]
<script setup lang="ts">
import { DynamicInput } from "@bysages/vue";
import { ref } from "vue";
const emails = ref<string[]>(["[email protected]", ""]);
</script>
<template>
<div class="grid gap-3 max-w-96">
<DynamicInput v-model="emails" placeholder="[email protected]" />
<p class="m-0 text-sm text-tertiary">values: {{ JSON.stringify(emails) }}</p>
</div>
</template>
Between 1 and 3 codes
<script setup lang="ts">
import { DynamicInput } from "@bysages/vue";
import { ref } from "vue";
const codes = ref<string[]>(["QH-01", "CL-02"]);
</script>
<template>
<div class="grid gap-3 max-w-96">
<DynamicInput v-model="codes" :min="1" :max="3" add-label="Add code" placeholder="Code" />
<p class="m-0 text-sm text-tertiary">Between 1 and 3 codes</p>
</div>
</template>
#属性
#DynamicInput
DynamicInput:动态输入列表。每行一个 Input,带一个低调的移除按钮,末尾提供添加行。列表受控:每次编辑都会发出新的数组,父级数组是唯一数据源。删除不会少于 min,添加不会超过 max,且组始终保留一行;否则清空后的录入列表会让使用者无处输入。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
modelValue | Array as PropType<string[]> | () => [""] | 每行的值;每个条目渲染一个 Input |
min | Number | 0 | 组件组保留的最少行数;达到下限时删除按钮不再可用 |
max | Number | undefined | 组件组最多可达到的行数;达到上限后添加按钮不再可用 |
placeholder | String | undefined | — |
addLabel | String | "Add entry" | 添加按钮显示的文本 |
disabled | Boolean | false | — |
invalid | Boolean | false | — |
size | String as PropType<"sm" | "md" | "lg"> | "md" | 每行输入框和删除按钮使用的尺寸档位 |