VEUI

VEUI on GitHub
Play!中文

TagInput

Examples

Size variants

Available ui prop values for size: xs / s / m / l.

Large
Normal
Small
Extra small
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-tag-input
      v-model="valueL"
      ui="l"
    />
  </section>
  <section>
    <veui-tag-input v-model="valueM"/>
  </section>
  <section>
    <veui-tag-input
      v-model="valueS"
      ui="s"
    />
  </section>
  <section>
    <veui-tag-input
      v-model="valueXs"
      ui="xs"
    />
  </section>
</article>
</template>

<script>
import { TagInput } from 'veui'

export default {
  components: {
    'veui-tag-input': TagInput
  },
  data () {
    return {
      valueS: ['Small'],
      valueL: ['Large'],
      valueM: ['Normal'],
      valueXs: ['Extra small']
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

Read-only

Use the readonly prop to set the input to readonly state.

Large
Normal
Small
Extra small
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-checkbox v-model="readonly">
      Read-only
    </veui-checkbox>
  </section>
  <section>
    <section>
      <veui-tag-input
        v-model="valueL"
        ui="l"
        :readonly="readonly"
      />
    </section>
    <section>
      <veui-tag-input
        v-model="valueM"
        :readonly="readonly"
      />
    </section>
    <section>
      <veui-tag-input
        v-model="valueS"
        ui="s"
        :readonly="readonly"
      />
    </section>
    <section>
      <veui-tag-input
        v-model="valueXs"
        ui="xs"
        :readonly="readonly"
      />
    </section>
  </section>
</article>
</template>

<script>
import { TagInput, Checkbox } from 'veui'

export default {
  components: {
    'veui-tag-input': TagInput,
    'veui-checkbox': Checkbox
  },
  data () {
    return {
      valueS: ['Small'],
      valueL: ['Large'],
      valueM: ['Normal'],
      valueXs: ['Extra small'],
      readonly: true
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

Disabled

Use the disabled prop to disable the input.

Large
Normal
Small
Extra small
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-checkbox v-model="disabled">
      Disabled
    </veui-checkbox>
  </section>
  <section>
    <section>
      <veui-tag-input
        v-model="valueL"
        ui="l"
        :disabled="disabled"
      />
    </section>
    <section>
      <veui-tag-input
        v-model="valueM"
        :disabled="disabled"
      />
    </section>
    <section>
      <veui-tag-input
        v-model="valueS"
        ui="s"
        :disabled="disabled"
      />
    </section>
    <section>
      <veui-tag-input
        v-model="valueXs"
        ui="xs"
        :disabled="disabled"
      />
    </section>
  </section>
</article>
</template>

<script>
import { TagInput, Checkbox } from 'veui'

export default {
  components: {
    'veui-tag-input': TagInput,
    'veui-checkbox': Checkbox
  },
  data () {
    return {
      valueS: ['Small'],
      valueL: ['Large'],
      valueM: ['Normal'],
      valueXs: ['Extra small'],
      disabled: true
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

Allow duplicate

Use the allow-duplicate prop to allow duplicate tags.

Steve
Steve
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-checkbox v-model="allowDuplicate">
      Allow duplicate
    </veui-checkbox>
  </section>
  <section>
    <veui-tag-input
      v-model="value"
      :allow-duplicate="allowDuplicate"
    />
  </section>
</article>
</template>

<script>
import { TagInput, Checkbox } from 'veui'

export default {
  components: {
    'veui-tag-input': TagInput,
    'veui-checkbox': Checkbox
  },
  data () {
    return {
      allowDuplicate: true,
      value: ['Steve', 'Steve']
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

Maximum tags

Use the max prop to limit the maximum number of tags.

Max tag count

Tony
Steve
2/3
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <h4>Max tag count</h4>
    <veui-number-input v-model="max"/>
  </section>
  <section>
    <veui-tag-input
      v-model="value"
      :max="max"
    />
  </section>
</article>
</template>

<script>
import { TagInput, NumberInput } from 'veui'

export default {
  components: {
    'veui-tag-input': TagInput,
    'veui-number-input': NumberInput
  },
  data () {
    return {
      max: 3,
      value: ['Tony', 'Steve']
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

Maximum characters

Use the maxlength prop to limit the maximum number of characters.

Max tag length

Tony
Steve
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <h4>Max tag length</h4>
    <veui-number-input v-model="maxlength"/>
  </section>
  <section>
    <veui-tag-input
      v-model="value"
      :maxlength="maxlength"
    />
  </section>
</article>
</template>

<script>
import { TagInput, NumberInput } from 'veui'

export default {
  components: {
    'veui-tag-input': TagInput,
    'veui-number-input': NumberInput
  },
  data () {
    return {
      maxlength: 6,
      value: ['Tony', 'Steve']
    }
  }
}
</script>

<style lang="less" scoped>
section {
  margin-bottom: 1em;
}
</style>

Custom tags

Use the tag slot to customize the display of tags.

Stephen
Wanda
Carol
Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-tag-input v-model="value">
      <template #tag="{ tag, attrs, listeners }">
        <veui-tag
          ui="bordered"
          color="violet"
          v-bind="attrs"
          v-on="listeners"
        >
          {{ tag }}
        </veui-tag>
      </template>
    </veui-tag-input>
  </section>
</article>
</template>

<script>
import { TagInput, Tag } from 'veui'

export default {
  components: {
    'veui-tag-input': TagInput,
    'veui-tag': Tag
  },
  data () {
    return {
      value: ['Stephen', 'Wanda', 'Carol']
    }
  }
}
</script>

API

Props

NameTypeDefaultDescription
uistring-

Predefined styles.

ValueDescription
xsExtra small size style.
sSmall size style.
mMedium size style.
lLarge size style.
valuestring-

v-model

The value of the input tags list.

input-valuestring''

.sync

The value of the text input box.

disabledbooleanfalseWhether the tag input is disabled.
readonlybooleanfalseWhether the tag input is read-only.
placeholderstring-Input placeholder.
clearablebooleanfalseWhether to show the clear button.
autofocusbooleanfalseWhether to autofocus the tag input.
maxlengthnumber-The maximum number of characters that can be entered.
maxnumber-The maximum number of tags that can be added.
strictboolean | Objectfalse

When boolean, it configures both maxlength and max restrictions in strict mode. When Object, it can be configured separately.

NameTypeDescription
maxlengthbooleanWhether to strictly input the length and prohibit input beyond the limit.
maxbooleanWhether to strictly limit the number of tags entered, and new tags added beyond the limit will not take effect.
get-lengthfunction(string): number-A custom function to calculate the length of characters.
allow-duplicatebooleanfalseWhether to allow duplicate tags.

Slots

NameDescription
tag

The added tag items.

Default content: The tag items rendered by the Tag component.

NameTypeDescription
attrsObjectProperties that need to be output to the standard Tag component. You can use v-bind="attrs" for unified output.
listenersObjectEvent listeners that need to be output to the standard Tag component. You can use v-on="listeners" for unified output.
tagstringThe text value of the tag item.
indexfunction(value: *): voidUsed to switch selected items.
keystringThe key of the tag item, which must be bound to a single item.
invalidbooleanWhether it is in an invalid state of validation.
readonlybooleanWhether it is in read-only state.
disabledbooleanWhether it is in a disabled state.
editfunction(): voidEdit the current tag item.
removefunction(): voidRemove the current tag item.

Events

NameDescription
change

v-model

Triggered when the content of the tag list changes. The callback function takes (value: Array<string>) as its parameter, where value is the list of tags that have been entered.

input

.sync

Triggered when the input content in the text box changes. The callback function takes (inputValue: string) as its parameter, where inputValue is the text content of the input box.

clearTriggered when the clear button is clicked.

In addition, TagInput supports the following native events:

auxclick, click, contextmenu, dblclick, mousedown, mouseenter, mouseleave, mousemove, mouseover, mouseout, mouseup, select, wheel, keydown, keypress, keyup, focus, blur, focusin, and focusout.

The parameters of the callback function are all native event objects.

Icons

NameDescription
removeThe clear button.
Edit this page on GitHubEdit
© Baidu, Inc. 2024