注册 X
提交 注:点击提交后系统会发送邮件到邮箱验证!(仅支持中国大陆邮箱)
我已阅读并同意 服务条款
首页 > IT技术笔记 > 查看笔记

vant-Button 按钮

介绍

按钮用于触发一个操作,如提交表单。

引入

        
        
      

代码演示


按钮类型


按钮支持 `default`、`primary`、`info`、`warning`、`danger` 五种类型,默认为 `default`。

        
        
      

朴素按钮

通过 `plain` 属性将按钮设置为朴素按钮,朴素按钮的文字为按钮颜色,背景为白色。

        
        
      

细边框

设置 `hairline` 属性可以展示 0.5px 的细边框。

        
        
      

禁用状态

通过 `disabled` 属性来禁用按钮,禁用状态下按钮不可点击。

        
        
      

加载状态

通过 `loading` 属性设置按钮为加载状态,加载状态下默认会隐藏按钮文字,可以通过 `loading-text` 设置加载状态下的文字。

        
        
      

按钮形状

通过 `square` 设置方形按钮,通过 `round` 设置圆形按钮。

        
        
      

图标按钮

通过 `icon` 属性设置按钮图标,支持 Icon 组件里的所有图标,也可以传入图标 URL。

        
        
      

按钮尺寸

支持 `large`、`normal`、`small`、`mini` 四种尺寸,默认为 `normal`。

        
        
      

块级元素

按钮在默认情况下为行内块级元素,通过 `block` 属性可以将按钮的元素类型设置为块级元素。

        
        
      

页面导航

可以通过 `url` 属性进行 URL 跳转,或通过 `to` 属性进行路由跳转。

        
        
      

自定义颜色

通过 `color` 属性可以自定义按钮的颜色。

        
        
      

API

Props

参数说明类型默认值
type类型,可选值为 primary info warning dangerstringdefault
size尺寸,可选值为 large small ministringnormal
text按钮文字string-
color按钮颜色,支持传入 linear-gradient 渐变色string-
icon左侧[图标名称](https://youzan.github.io/vant/v2/#/zh-CN/icon)或图片链接string-
icon-prefix v2.6.0图标类名前缀,同 Icon 组件的 [class-prefix 属性](https://youzan.github.io/vant/v2/#/zh-CN/icon#props)stringvan-icon
icon-position v2.10.7图标展示位置,可选值为 rightstringleft
tag按钮根节点的 HTML 标签stringbutton
native-type原生 button 标签的 type 属性string-
block是否为块级元素booleanfalse
plain是否为朴素按钮booleanfalse
square是否为方形按钮booleanfalse
round是否为圆形按钮booleanfalse
disabled是否禁用按钮booleanfalse
hairline是否使用 0.5px 边框booleanfalse
loading是否显示为加载状态booleanfalse
loading-text加载状态提示文字string-
loading-type[加载图标类型](https://youzan.github.io/vant/v2/#/zh-CN/loading),可选值为 spinnerstringcircular
loading-size加载图标大小string20px
url点击后跳转的链接地址string-
to点击后跳转的目标路由对象,同 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to)*stringobject*-
replace是否在跳转时替换当前页面历史booleanfalse

Events

事件名说明回调参数
click点击按钮,且按钮状态不为加载或禁用时触发event: Event
touchstart开始触摸按钮时触发event: TouchEvent

Slots

名称说明
default按钮内容
icon v2.12.21自定义图标
loading v2.10.1自定义加载图标

样式变量

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

主题定制

名称默认值描述
@button-mini-height24px-
@button-mini-font-size@font-size-xs-
@button-small-height32px-
@button-small-font-size@font-size-sm-
@button-normal-font-size@font-size-md-
@button-large-height50px-
@button-default-height44px-
@button-default-line-height1.2-
@button-default-font-size@font-size-lg-
@button-default-color@text-color-
@button-default-background-color@white-
@button-default-border-color@border-color-
@button-primary-color@white-
@button-primary-background-color@green-
@button-primary-border-color@green-
@button-info-color@white-
@button-info-background-color@blue-
@button-info-border-color@blue-
@button-danger-color@white-
@button-danger-background-color@red-
@button-danger-border-color@red-
@button-warning-color@white-
@button-warning-background-color@orange-
@button-warning-border-color@orange-
@button-border-width@border-width-base-
@button-border-radius@border-radius-sm-
@button-round-border-radius@border-radius-max-
@button-plain-background-color@white-
@button-disabled-opacity@disabled-opacity-

图片效果:


 打赏        分享



评论

邮箱: 昵称: