<template>
<div class="flex gap-2">
<el-tag type="primary">Tag 1</el-tag>
<el-tag type="success">Tag 2</el-tag>
<el-tag type="info">Tag 3</el-tag>
<el-tag type="warning">Tag 4</el-tag>
<el-tag type="danger">Tag 5</el-tag>
</div>
</template>
<template>
<div class="flex gap-2">
<el-tag v-for="tag in tags" :key="tag.name" closable :type="tag.type">
{{ tag.name }}
</el-tag>
</div>
</template>
<script setup>
import { ref } from 'vue'
import type { TagProps } from 'element-plus'
interface TagsItem {
name: string
type: TagProps['type']
}
const tags = ref<TagsItem[]>([
{ name: 'Tag 1', type: 'primary' },
{ name: 'Tag 2', type: 'success' },
{ name: 'Tag 3', type: 'info' },
{ name: 'Tag 4', type: 'warning' },
{ name: 'Tag 5', type: 'danger' },
])
</script>
<template>
<div class="flex gap-2">
<el-tag size="large">Large</el-tag>
<el-tag>Default</el-tag>
<el-tag size="small">Small</el-tag>
</div>
</template>
<template>
<div class="flex gap-2">
<span>Dark</span>
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="dark"
>
{{ item.label }}
</el-tag>
</div>
<div class="flex gap-2 mt-4">
<span>Light</span>
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="light"
>
{{ item.label }}
</el-tag>
</div>
<div class="flex gap-2 mt-4">
<span>Plain</span>
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="plain"
>
{{ item.label }}
</el-tag>
</div>
</template>
<script setup>
import { ref } from 'vue'
import type { TagProps } from 'element-plus'
type Item = { type: TagProps['type']; label: string }
const items = ref<Array<Item>>([
{ type: 'primary', label: 'Tag 1' },
{ type: 'success', label: 'Tag 2' },
{ type: 'info', label: 'Tag 3' },
{ type: 'warning', label: 'Tag 4' },
{ type: 'danger', label: 'Tag 5' },
])
</script>
<template>
<div class="flex gap-2">
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="dark"
round
>
{{ item.label }}
</el-tag>
</div>
<div class="flex gap-2 mt-4">
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="light"
round
>
{{ item.label }}
</el-tag>
</div>
<div class="flex gap-2 mt-4">
<el-tag
v-for="item in items"
:key="item.label"
:type="item.type"
effect="plain"
round
>
{{ item.label }}
</el-tag>
</div>
</template>
<script setup>
import { ref } from 'vue'
import type { TagProps } from 'element-plus'
type Item = { type: TagProps['type']; label: string }
const items = ref<Array<Item>>([
{ type: 'primary', label: 'Tag 1' },
{ type: 'success', label: 'Tag 2' },
{ type: 'info', label: 'Tag 3' },
{ type: 'warning', label: 'Tag 4' },
{ type: 'danger', label: 'Tag 5' },
])
</script>
<template>
<div class="flex gap-2">
<el-check-tag checked>Checked</el-check-tag>
<el-check-tag :checked="checked" @change="onChange">Toggle me</el-check-tag>
<el-check-tag disabled>Disabled</el-check-tag>
</div>
<div class="flex gap-2 mt-4">
<el-check-tag :checked="checked1" type="primary" @change="onChange1">
Tag 1
</el-check-tag>
<el-check-tag :checked="checked2" type="success" @change="onChange2">
Tag 2
</el-check-tag>
<el-check-tag :checked="checked3" type="info" @change="onChange3">
Tag 3
</el-check-tag>
<el-check-tag :checked="checked4" type="warning" @change="onChange4">
Tag 4
</el-check-tag>
<el-check-tag :checked="checked5" type="danger" @change="onChange5">
Tag 5
</el-check-tag>
<el-check-tag
:checked="checked6"
disabled
type="success"
@change="onChange6"
>
Tag 6
</el-check-tag>
</div>
</template>
<script setup>
import { ref } from 'vue'
const checked = ref(false)
const checked1 = ref(true)
const checked2 = ref(true)
const checked3 = ref(true)
const checked4 = ref(true)
const checked5 = ref(true)
const checked6 = ref(true)
const onChange = (status: boolean) => {
checked.value = status
}
const onChange1 = (status: boolean) => {
checked1.value = status
}
const onChange2 = (status: boolean) => {
checked2.value = status
}
const onChange3 = (status: boolean) => {
checked3.value = status
}
const onChange4 = (status: boolean) => {
checked4.value = status
}
const onChange5 = (status: boolean) => {
checked5.value = status
}
const onChange6 = (status: boolean) => {
checked6.value = status
}
</script>
Tag API
Tag Attributes
属性名 | 说明 | 类型 | 默认 |
---|
type | Tag 的类型 | enum | primary |
closable | 是否可关闭 | boolean | false |
disable-transitions | 是否禁用渐变动画 | boolean | false |
hit | 是否有边框描边 | boolean | false |
color | 背景色 | string | — |
size | Tag 的尺寸 | enum | — |
effect | Tag 的主题 | enum | light |
round | Tag 是否为圆形 | boolean | false |
Tag Events
事件名 | 说明 | Type |
---|
click | 点击 Tag 时触发的事件 | Function |
close | 关闭 Tag 时触发的事件 | Function |
Tag Slots
CheckTag API
CheckTag Attributes
属性名 | 说明 | 类型 | 默认 |
---|
checked / v-model:checked | 是否选中 | boolean | false |
disabled 2.8.2 | 是否禁用 | boolean | false |
type 2.5.4 | CheckTag 类型 | enum | primary |
CheckTag Events
事件名 | 说明 | 类型 |
---|
change | 点击 Check Tag 时触发的事件 | Function |
CheckTag Slots