Tag 标记

引入

  1. import Vue from 'vue';
  2. import { Tag } from 'vant';
  3. Vue.use(Tag);

代码演示

基础用法

通过type属性控制标签颜色,默认为灰色

  1. <van-tag>标签</van-tag>
  2. <van-tag type="primary">标签</van-tag>
  3. <van-tag type="success">标签</van-tag>
  4. <van-tag type="danger">标签</van-tag>
  5. <van-tag type="warning">标签</van-tag>

圆角样式

通过round设置为圆角样式

  1. <van-tag round>标签</van-tag>
  2. <van-tag round type="primary">标签</van-tag>
  3. <van-tag round type="success">标签</van-tag>
  4. <van-tag round type="danger">标签</van-tag>
  5. <van-tag round type="warning">标签</van-tag>

标记样式

通过mark设置为标记样式(半圆角)

  1. <van-tag mark>标签</van-tag>
  2. <van-tag mark type="primary">标签</van-tag>
  3. <van-tag mark type="success">标签</van-tag>
  4. <van-tag mark type="danger">标签</van-tag>
  5. <van-tag mark type="warning">标签</van-tag>

空心样式

设置plain属性设置为空心样式

  1. <van-tag plain>标签</van-tag>
  2. <van-tag plain type="primary">标签</van-tag>
  3. <van-tag plain type="success">标签</van-tag>
  4. <van-tag plain type="danger">标签</van-tag>
  5. <van-tag plain type="warning">标签</van-tag>

自定义颜色

  1. <van-tag color="#f2826a">标签</van-tag>
  2. <van-tag color="#f2826a" plain>标签</van-tag>
  3. <van-tag color="#7232dd">标签</van-tag>
  4. <van-tag color="#7232dd" plain>标签</van-tag>
  5. <van-tag color="#ffe1e1" text-color="#ad0000">标签</van-tag>

标签大小

  1. <van-tag type="danger">标签</van-tag>
  2. <van-tag type="danger" size="medium">标签</van-tag>
  3. <van-tag type="danger" size="large">标签</van-tag>

可关闭标签

添加closeable属性表示标签是可关闭的,关闭标签时会触发close事件,在close事件中可以执行隐藏标签的逻辑

  1. <van-tag
  2. v-if="show.primary"
  3. closeable
  4. size="medium"
  5. type="primary"
  6. @close="close('primary')"
  7. >
  8. 标签
  9. </van-tag>
  10. <van-tag
  11. v-if="show.success"
  12. closeable
  13. size="medium"
  14. type="success"
  15. @close="close('success')"
  16. >
  17. 标签
  18. </van-tag>
  1. export default {
  2. data() {
  3. return {
  4. show: {
  5. primary: true,
  6. success: true
  7. }
  8. }
  9. },
  10. methods: {
  11. close(type) {
  12. this.show[type] = false;
  13. }
  14. }
  15. }

API

Props

参数说明类型默认值
type类型,可选值为primary success danger warningstringdefault
size大小, 可选值为large mediumstring-
color标签颜色string-
plain是否为空心样式booleanfalse
round是否为圆角样式booleanfalse
mark是否为标记样式booleanfalse
text-color文本颜色,优先级高于color属性stringwhite
closeable v2.2.9是否为可关闭标签booleanfalse

Slots

名称说明
default标签显示内容

Events

事件名说明回调参数
click点击时触发event: Event
close关闭标签时触发-

Tag 标记 - 图1