Skip to content

Button - Vant 4

Button

🎯 Ready to make things happen with a click? Let's dive into the Button component!

Intro 📖

The heart of user interaction! Buttons are your gateway to action - whether it's submitting forms, navigating pages, or triggering any exciting functionality! 🚀 Click, tap, and make magic happen! ✨

Install 📦

Let's get clicking! Register the component globally via app.use - it's super easy! 🎯 Check out our Component Registration guide for more installation options.

js
import { createApp } from'vue'; import { Button } from'vant'; const app = createApp(); app.use(Button);

Usage 🎮

Type 🎨

Express yourself with five amazing button types! Choose from default, primary, success, warning, and danger - each with its own personality and purpose! 🌈

html

Plain 🤍

Keep it simple and elegant! Use the plain prop for a minimalist look where the text color matches the button theme with a clean white background. Perfect for subtle actions! ✨

html

Hairline 📏

Precision matters! The hairline prop creates ultra-thin borders (0.5px) for that crisp, modern look. It's all about the details! 🔍

html

Disabled 🚫

Sometimes buttons need a break! Use the disabled prop to prevent clicks and give visual feedback that an action isn't available right now. 😴

html

Loading ⏳

Show users that something awesome is happening! The loading prop displays a spinning indicator while hiding the button text. Want custom loading text? Use loading-text to keep users informed! 🔄

html

Shape 🔲

Express your style! Choose square for that modern, geometric look or round for smooth, friendly vibes. Shape matters in design! 🎨

html

Icon 🎯

Add visual flair to your buttons! Use the icon prop to place icons on the left side, or switch it up with icon-position to move icons around. Icons speak louder than words! 🔥

html

Size 📏

Size it right for every occasion! Pick from large (bold statements), normal (everyday actions), small (compact spaces), or mini (tiny but mighty). Default is normal - the perfect balance! ⚖️

html

Block 📱

Take up the full stage! The block prop makes your button stretch to fill its parent's width - perfect for mobile interfaces and call-to-action buttons! 📏

html

Route 🧭

Navigate like a pro! Use url for simple redirects or to for Vue Router navigation. Your buttons can be gateways to anywhere! 🚀

html

Custom Color 🎨

Make it uniquely yours! Use the color prop to set any color you want - solid colors, gradients, you name it! Let your creativity shine through! 🌈

html

Animated Button 🎬

Bring your buttons to life! Combine Button with our Swipe component to create mesmerizing animated effects with smooth vertical scrolling. Motion makes magic! ✨

html

API

Props

AttributeDescriptionTypeDefault
typeCan be set to primary``success``warning``dangerstringdefault
sizeCan be set to large``small``ministringnormal
textTextstring-
colorColor, support linear-gradientstring-
iconLeft Iconstring-
icon-prefixIcon className prefixstringvan-icon
icon-positionIcon position, can be set to rightstringleft
tagHTML Tagstringbutton
native-typeNative Type Attributestringbutton
plainWhether to be plain buttonbooleanfalse
blockWhether to set display blockbooleanfalse
roundWhether to be round buttonbooleanfalse
squareWhether to be square buttonbooleanfalse
disabledWhether to disable buttonbooleanfalse
loadingWhether to show loading statusbooleanfalse
loading-textLoading textstring-
loading-typeLoading type, can be set to spinnerstringcircular
loading-sizeLoading icon size*numberstring*
urlLink URLstring-
toThe target route should navigate to when clicked on, same as the to prop of Vue Router*stringobject*

| replace | If true, the navigation will not leave a history record | boolean | false |

Events

EventDescriptionArguments
clickEmitted when button is clicked and not disabled or loadingevent: MouseEvent
touchstartEmitted when button is touchedevent: TouchEvent

Slots

NameDescription
defaultDefault slot
iconCustom icon
loadingCustom loading icon

Types

The component exports the following type definitions:

ts
importtype { ButtonType, ButtonSize, ButtonProps, ButtonNativeType, ButtonIconPosition, } from'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-button-mini-height24px-
--van-button-mini-padding0 var(--van-padding-base)-
--van-button-mini-font-sizevar(--van-font-size-xs)-
--van-button-small-height32px-
--van-button-small-padding0 var(--van-padding-xs)-
--van-button-small-font-sizevar(--van-font-size-sm)-
--van-button-normal-font-sizevar(--van-font-size-md)-
--van-button-normal-padding0 15px-
--van-button-large-height50px-
--van-button-default-height44px-
--van-button-default-line-height1.2-
--van-button-default-font-sizevar(--van-font-size-lg)-
--van-button-default-colorvar(--van-text-color)-
--van-button-default-backgroundvar(--van-background-2)-
--van-button-default-border-colorvar(--van-gray-4)-
--van-button-primary-colorvar(--van-white)-
--van-button-primary-backgroundvar(--van-primary-color)-
--van-button-primary-border-colorvar(--van-primary-color)-
--van-button-success-colorvar(--van-white)-
--van-button-success-backgroundvar(--van-success-color)-
--van-button-success-border-colorvar(--van-success-color)-
--van-button-danger-colorvar(--van-white)-
--van-button-danger-backgroundvar(--van-danger-color)-
--van-button-danger-border-colorvar(--van-danger-color)-
--van-button-warning-colorvar(--van-white)-
--van-button-warning-backgroundvar(--van-warning-color)-
--van-button-warning-border-colorvar(--van-warning-color)-
--van-button-border-widthvar(--van-border-width)-
--van-button-radiusvar(--van-radius-md)-
--van-button-round-radiusvar(--van-radius-max)-
--van-button-plain-backgroundvar(--van-white)-
--van-button-disabled-opacityvar(--van-disabled-opacity)-
--van-button-icon-size1.2em-
--van-button-loading-icon-size20px-

Enterprise-level mobile solution based on Vant