/*! For license information please see 3624.20d235bc.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["3624"],{20874:function(s,a,n){"use strict";n.r(a);var t=n("80681");let l=["innerHTML"];a.default={setup:()=>({html:""}),render:()=>((0,t.wg)(),(0,t.iD)("div",{class:"van-doc-markdown-body",innerHTML:'
Display a small badge or a red dot to the top-right of its child.
\nRegister component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Badge } from 'vant';\n\nconst app = createApp();\napp.use(Badge);\n
\n<van-badge :content="5">\n <div class="child" />\n</van-badge>\n<van-badge :content="10">\n <div class="child" />\n</van-badge>\n<van-badge content="Hot">\n <div class="child" />\n</van-badge>\n<van-badge dot>\n <div class="child" />\n</van-badge>\n\n<style>\n .child {\n width: 40px;\n height: 40px;\n background: #f2f3f5;\n border-radius: 4px;\n }\n</style>\n
\n<van-badge :content="20" max="9">\n <div class="child" />\n</van-badge>\n<van-badge :content="50" max="20">\n <div class="child" />\n</van-badge>\n<van-badge :content="200" max="99">\n <div class="child" />\n</van-badge>\n
\n<van-badge :content="5" color="#1989fa">\n <div class="child" />\n</van-badge>\n<van-badge :content="10" color="#1989fa">\n <div class="child" />\n</van-badge>\n<van-badge dot color="#1989fa">\n <div class="child" />\n</van-badge>\n
\nUse content
slot to custom the content of badge.
<van-badge>\n <div class="child" />\n <template #content>\n <van-icon name="success" class="badge-icon" />\n </template>\n</van-badge>\n<van-badge>\n <div class="child" />\n <template #content>\n <van-icon name="cross" class="badge-icon" />\n </template>\n</van-badge>\n<van-badge>\n <div class="child" />\n <template #content>\n <van-icon name="down" class="badge-icon" />\n </template>\n</van-badge>\n
\n.badge-icon {\n display: block;\n font-size: 10px;\n line-height: 16px;\n}\n
\nUse position
prop to set the position of badge.
<van-badge :content="10" position="top-left">\n <div class="child" />\n</van-badge>\n<van-badge :content="10" position="bottom-left">\n <div class="child" />\n</van-badge>\n<van-badge :content="10" position="bottom-right">\n <div class="child" />\n</van-badge>\n
\n<van-badge :content="20" />\n\n<van-badge :content="200" max="99" />\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
content | \nBadge content | \nnumber | string | \n- | \n
color | \nBackground color | \nstring | \n#ee0a24 | \n
dot | \nWhether to show dot | \nboolean | \nfalse | \n
max | \nMax value, show {max}+ when exceed, only works when content is number | \nnumber | string | \n- | \n
offset | \nOffset of badge dot, the two items of the array correspond to the horizontal and vertical offsets | \n[number | string, number | string] | \n- | \n
show-zero | \nWhether to show badge when content is zero | \nboolean | \ntrue | \n
position | \nBadge position, can be set to top-left bottom-left bottom-right | \nstring | \ntop-right | \n
Name | \nDescription | \n
---|---|
default | \nDefault slot | \n
content | \nCustom badge content | \n
The component exports the following type definitions:
\nimport type { BadgeProps, BadgePosition } from 'vant';\n
\nThe component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
\nName | \nDefault Value | \nDescription | \n
---|---|---|
--van-badge-size | \n16px | \n- | \n
--van-badge-color | \nvar(--van-white) | \n- | \n
--van-badge-padding | \n0 3px | \n- | \n
--van-badge-font-size | \nvar(--van-font-size-sm) | \n- | \n
--van-badge-font-weight | \nvar(--van-font-bold) | \n- | \n
--van-badge-border-width | \nvar(--van-border-width) | \n- | \n
--van-badge-background | \nvar(--van-danger-color) | \n- | \n
--van-badge-dot-color | \nvar(--van-danger-color) | \n- | \n
--van-badge-dot-size | \n8px | \n- | \n
--van-badge-font | \n-apple-system-font, Helvetica Neue, Arial, sans-serif | \n- | \n