codecamp

Vant2 Tag 标签

引入

import Vue from 'vue';
import { Tag } from 'vant';

Vue.use(Tag);

代码演示

基础用法

通过 type 属性控制标签颜色。

<van-tag type="primary">标签</van-tag>
<van-tag type="success">标签</van-tag>
<van-tag type="danger">标签</van-tag>
<van-tag type="warning">标签</van-tag>

空心样式

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

<van-tag plain type="primary">标签</van-tag>

圆角样式

通过 round 设置为圆角样式。

<van-tag round type="primary">标签</van-tag>

标记样式

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

<van-tag mark type="primary">标签</van-tag>

可关闭标签

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

<van-tag v-if="show" closeable size="medium" type="primary" @close="close">
  标签
</van-tag>
export default {
  data() {
    return {
      show: true,
    };
  },
  methods: {
    close() {
      this.show = false;
    },
  },
};

标签大小

通过 size 属性调整标签大小。

<van-tag type="primary">标签</van-tag>
<van-tag type="primary" size="medium">标签</van-tag>
<van-tag type="primary" size="large">标签</van-tag>

自定义颜色

通过 colortext-color 属性设置标签颜色。

<van-tag color="#7232dd">标签</van-tag>
<van-tag color="#ffe1e1" text-color="#ad0000">标签</van-tag>
<van-tag color="#7232dd" plain>标签</van-tag>

API

Props

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

Slots

名称 说明
default 标签显示内容

Events

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

样式变量

组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制

名称 默认值 描述
@tag-padding 0 @padding-base -
@tag-text-color @white -
@tag-font-size @font-size-sm -
@tag-border-radius 2px -
@tag-line-height 16px -
@tag-medium-padding 2px 6px -
@tag-large-padding @padding-base @padding-xs -
@tag-large-border-radius @border-radius-md -
@tag-large-font-size @font-size-md -
@tag-round-border-radius @border-radius-max -
@tag-danger-color @red -
@tag-primary-color @blue -
@tag-success-color @green -
@tag-warning-color @orange -
@tag-default-color @gray-6 -
@tag-plain-background-color @white -
Vant2 Swipe 轮播
Vant2 Grid 宫格
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }