/*! For license information please see 7858.af0248af.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["7858"],{66112:function(n,t,s){"use strict";s.r(t);var a=s("80681");let l=["innerHTML"];t.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'
Buttons are used to trigger an action, such as submitting a form.
\nRegister component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Button } from 'vant';\n\nconst app = createApp();\napp.use(Button);\n
\nThe Button supports five types: default
, primary
, success
, warning
, and danger
. The default type is default
.
<van-button type="primary">Primary</van-button>\n<van-button type="success">Success</van-button>\n<van-button type="default">Default</van-button>\n<van-button type="danger">Danger</van-button>\n<van-button type="warning">Warning</van-button>\n
\nUse the plain
prop to set the button as a plain button. The text color of a plain button is the same as the button color, and the background is white.
<van-button plain type="primary">Plain</van-button>\n<van-button plain type="success">Plain</van-button>\n
\nSetting the hairline
prop to display a border with a thickness of 0.5px.
<van-button plain hairline type="primary">Hairline</van-button>\n<van-button plain hairline type="success">Hairline</van-button>\n
\nUse the disabled
prop to disable the button. In the disabled state, the button cannot be clicked.
<van-button disabled type="primary">Disabled</van-button>\n<van-button disabled type="success">Disabled</van-button>\n
\nSet the button as a loading state using the loading
prop. In the loading state, the button text is hidden by default. You can set the text for the loading state using the loading-text
property.
<van-button loading type="primary" />\n<van-button loading type="primary" loading-type="spinner" />\n<van-button loading type="success" loading-text="Loading..." />\n
\nUse the square
prop to set the button as square-shaped and the round
prop to set it as round-shaped.
<van-button square type="primary">Square</van-button>\n<van-button round type="success">Round</van-button>\n
\nUse the icon
prop to set the button icon. It supports all icons from the Icon component or you can pass a custom icon URL.
<van-button icon="plus" type="primary" />\n<van-button icon="plus" type="primary">Button</van-button>\n<van-button\n icon="https://fastly.jsdelivr.net/npm/@vant/assets/user-active.png"\n type="primary"\n>\n Button\n</van-button>\n
\nFour sizes are supported: large
, normal
, small
, and mini
. The default size is normal
.
<van-button type="primary" size="large">Large</van-button>\n<van-button type="primary" size="normal">Normal</van-button>\n<van-button type="primary" size="small">Small</van-button>\n<van-button type="primary" size="mini">Mini</van-button>\n
\nBy default, the button is an inline-block element. Use the block
prop to change the button element type to a block-level element.
<van-button type="primary" block>Block Element</van-button>\n
\nYou can use the url
prop for URL redirection or the to
prop for route navigation.
<van-button type="primary" url="https://github.com">URL</van-button>\n<van-button type="primary" to="index">Vue Router</van-button>\n
\nCustomize the button color using the color
prop.
<van-button color="#7232dd">Pure</van-button>\n<van-button color="#7232dd" plain>Pure</van-button>\n<van-button color="linear-gradient(to right, #ff6034, #ee0a24)">\n Gradient\n</van-button>\n
\nWith the combination of the Button and Swipe component, you can create an animated button effect with vertical scrolling.
\n<van-button type="danger" round>\n <van-swipe\n vertical\n class="notice-swipe"\n :autoplay="2000"\n :touchable="false"\n :show-indicators="false"\n >\n <van-swipe-item>Do Task</van-swipe-item>\n <van-swipe-item>Lottery</van-swipe-item>\n </van-swipe>\n</van-button>\n\n<style>\n .notice-swipe {\n height: 40px;\n line-height: 40px;\n }\n</style>\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
type | \nCan be set to primary success warning danger | \nstring | \ndefault | \n
size | \nCan be set to large small mini | \nstring | \nnormal | \n
text | \nText | \nstring | \n- | \n
color | \nColor, support linear-gradient | \nstring | \n- | \n
icon | \nLeft Icon | \nstring | \n- | \n
icon-prefix | \nIcon className prefix | \nstring | \nvan-icon | \n
icon-position | \nIcon position, can be set to right | \nstring | \nleft | \n
tag | \nHTML Tag | \nstring | \nbutton | \n
native-type | \nNative Type Attribute | \nstring | \nbutton | \n
plain | \nWhether to be plain button | \nboolean | \nfalse | \n
block | \nWhether to set display block | \nboolean | \nfalse | \n
round | \nWhether to be round button | \nboolean | \nfalse | \n
square | \nWhether to be square button | \nboolean | \nfalse | \n
disabled | \nWhether to disable button | \nboolean | \nfalse | \n
loading | \nWhether to show loading status | \nboolean | \nfalse | \n
loading-text | \nLoading text | \nstring | \n- | \n
loading-type | \nLoading type, can be set to spinner | \nstring | \ncircular | \n
loading-size | \nLoading icon size | \nnumber | string | \n20px | \n
url | \nLink URL | \nstring | \n- | \n
to | \nThe target route should navigate to when clicked on, same as the to prop of Vue Router | \nstring | object | \n- | \n
replace | \nIf true, the navigation will not leave a history record | \nboolean | \nfalse | \n
Event | \nDescription | \nArguments | \n
---|---|---|
click | \nEmitted when button is clicked and not disabled or loading | \nevent: MouseEvent | \n
touchstart | \nEmitted when button is touched | \nevent: TouchEvent | \n
Name | \nDescription | \n
---|---|
default | \nDefault slot | \n
icon | \nCustom icon | \n
loading | \nCustom loading icon | \n
The component exports the following type definitions:
\nimport type {\n ButtonType,\n ButtonSize,\n ButtonProps,\n ButtonNativeType,\n ButtonIconPosition,\n} 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-button-mini-height | \n24px | \n- | \n
--van-button-mini-padding | \n0 var(--van-padding-base) | \n- | \n
--van-button-mini-font-size | \nvar(--van-font-size-xs) | \n- | \n
--van-button-small-height | \n32px | \n- | \n
--van-button-small-padding | \n0 var(--van-padding-xs) | \n- | \n
--van-button-small-font-size | \nvar(--van-font-size-sm) | \n- | \n
--van-button-normal-font-size | \nvar(--van-font-size-md) | \n- | \n
--van-button-normal-padding | \n0 15px | \n- | \n
--van-button-large-height | \n50px | \n- | \n
--van-button-default-height | \n44px | \n- | \n
--van-button-default-line-height | \n1.2 | \n- | \n
--van-button-default-font-size | \nvar(--van-font-size-lg) | \n- | \n
--van-button-default-color | \nvar(--van-text-color) | \n- | \n
--van-button-default-background | \nvar(--van-background-2) | \n- | \n
--van-button-default-border-color | \nvar(--van-gray-4) | \n- | \n
--van-button-primary-color | \nvar(--van-white) | \n- | \n
--van-button-primary-background | \nvar(--van-primary-color) | \n- | \n
--van-button-primary-border-color | \nvar(--van-primary-color) | \n- | \n
--van-button-success-color | \nvar(--van-white) | \n- | \n
--van-button-success-background | \nvar(--van-success-color) | \n- | \n
--van-button-success-border-color | \nvar(--van-success-color) | \n- | \n
--van-button-danger-color | \nvar(--van-white) | \n- | \n
--van-button-danger-background | \nvar(--van-danger-color) | \n- | \n
--van-button-danger-border-color | \nvar(--van-danger-color) | \n- | \n
--van-button-warning-color | \nvar(--van-white) | \n- | \n
--van-button-warning-background | \nvar(--van-warning-color) | \n- | \n
--van-button-warning-border-color | \nvar(--van-warning-color) | \n- | \n
--van-button-border-width | \nvar(--van-border-width) | \n- | \n
--van-button-radius | \nvar(--van-radius-md) | \n- | \n
--van-button-round-radius | \nvar(--van-radius-max) | \n- | \n
--van-button-plain-background | \nvar(--van-white) | \n- | \n
--van-button-disabled-opacity | \nvar(--van-disabled-opacity) | \n- | \n
--van-button-icon-size | \n1.2em | \n- | \n
--van-button-loading-icon-size | \n20px | \n- | \n