Skip to content

Button 按钮

常用的操作按钮。

基础用法

使用 typeplainroundcircle来定义按钮的样式。

<template>
	<p>
		<vr-button>Default</vr-button>
		<vr-button type="primary">Primary</vr-button>
		<vr-button type="success">Success</vr-button>
		<vr-button type="info">Info</vr-button>
		<vr-button type="warning">Warning</vr-button>
		<vr-button type="danger">Danger</vr-button>
	</p>

	<p>
		<vr-button plain>Plain</vr-button>
		<vr-button type="primary" plain>Primary</vr-button>
		<vr-button type="success" plain>Success</vr-button>
		<vr-button type="info" plain>Info</vr-button>
		<vr-button type="warning" plain>Warning</vr-button>
		<vr-button type="danger" plain>Danger</vr-button>
	</p>

	<p>
		<vr-button round>Round</vr-button>
		<vr-button type="primary" round>Primary</vr-button>
		<vr-button type="success" round>Success</vr-button>
		<vr-button type="info" round>Info</vr-button>
		<vr-button type="warning" round>Warning</vr-button>
		<vr-button type="danger" round>Danger</vr-button>
	</p>

	<p>
		<vr-button icon="search" circle />
		<vr-button type="primary" icon="edit" circle />
		<vr-button type="success" icon="check" circle />
		<vr-button type="info" icon="message" circle />
		<vr-button type="warning" icon="star" circle />
		<vr-button type="danger" icon="trash" circle />
	</p>
</template>

禁用状态

你可以使用 disabled 属性来定义按钮是否被禁用。

<template>
	<p>
		<vr-button>Default</vr-button>
		<vr-button type="primary">Primary</vr-button>
		<vr-button type="success">Success</vr-button>
		<vr-button type="info">Info</vr-button>
		<vr-button type="warning">Warning</vr-button>
		<vr-button type="danger">Danger</vr-button>
	</p>
	<p>
		<vr-button disabled>Default</vr-button>
		<vr-button type="primary" disabled>Primary</vr-button>
		<vr-button type="success" disabled>Success</vr-button>
		<vr-button type="info" disabled>Info</vr-button>
		<vr-button type="warning" disabled>Warning</vr-button>
		<vr-button type="danger" disabled>Danger</vr-button>
	</p>
</template>

图标按钮

使用 icon属性来定义按钮的图标。

<template>
	<div>
		<vr-button type="primary" icon="edit" />
		<vr-button type="primary" icon="share" />
		<vr-button type="primary" icon="trash" />
		<vr-button type="primary" icon="search">Search</vr-button>
		<vr-button type="primary">
			Upload<vr-icon icon="upload" style="margin-left: 8px" />
		</vr-button>
	</div>
</template>

按钮组

使用 <vr-button-group> 对多个按钮分组。

<template>
	<p>
		<vr-button-group disabled>
			<vr-button type="primary" icon="arrow-left">Previous Page</vr-button>
			<vr-button type="primary">
				Next Page<vr-icon icon="arrow-right" style="margin-left: 8px" />
			</vr-button>
		</vr-button-group>
	</p>
	<p>
		<vr-button-group type="warning" size="small">
			<vr-button type="primary" icon="edit" round />
			<vr-button type="primary" icon="share" />
			<vr-button type="primary" icon="trash" round />
		</vr-button-group>
	</p>
</template>

加载状态

使用 loading属性来定义按钮的加载状态。

TIP

您可以使用 loading 插槽或 loadingIcon 属性自定义您的 loading 图标

ps: loading 插槽优先级高于 loadingIcon 属性

<template>
	<div>
		<vr-button type="primary" loading>Loading</vr-button>
		<vr-button type="primary" loading-icon="circle-notch" loading
			>Loading</vr-button
		>
		<vr-button type="primary" loading>
			<template #loading>
				<vr-icon style="margin-right: 6px" icon="star" spin />
			</template>
			Loading
		</vr-button>
	</div>
</template>

按钮尺寸

使用 size属性来定义按钮的尺寸。

<template>
	<p>
		<vr-button size="large">Large</vr-button>
		<vr-button>Default</vr-button>
		<vr-button size="small">Small</vr-button>
		<vr-button size="large" icon="search">Search</vr-button>
		<vr-button icon="search">Search</vr-button>
		<vr-button size="small" icon="search">Search</vr-button>
	</p>
	<p>
		<vr-button size="large" round>Large</vr-button>
		<vr-button round>Default</vr-button>
		<vr-button size="small" round>Small</vr-button>
		<vr-button size="large" icon="search" round>Search</vr-button>
		<vr-button icon="search" round>Search</vr-button>
		<vr-button size="small" icon="search" round>Search</vr-button>
	</p>
	<p>
		<vr-button size="large" icon="search" circle />
		<vr-button icon="search" circle />
		<vr-button size="small" icon="search" circle />
	</p>
</template>

Tag

可以自定义元素标签。例如,按钮,div,路由链接,nuxt 链接。

div
a

<template>
	<vr-button>button</vr-button>
	<vr-button tag="div" role="button" tabindex="0">div</vr-button>
	<vr-button
		type="primary"
		tag="a"
		href="https://breezli.cn/veyra/"
		target="_blank"
		rel="noopener noreferrer">
		a
	</vr-button>
</template>

节流模式

可以通过 useThrottle 属性来定义按钮是否使用节流模式 默认为 true。

<script setup>
	// import { VrMessage } from "veyra";
	function handleBtnClick() {
		VrMessage.info('btn click')
	}
</script>

<template>
	<p>
		<vr-button @click="handleBtnClick"> with throttle</vr-button>
		<vr-button @click="handleBtnClick" :use-throttle="false"
			>without throttle</vr-button
		>
	</p>
</template>

Button API

Props

NameDescriptionTypeDefault
size尺寸enum - 'large'| 'default'| 'small'
type类型enum - 'primary'| 'success'| 'warning'| 'danger'| 'info'info
plain是否为朴素按钮booleanfalse
round是否为圆角按钮booleanfalse
circle是否为圆形按钮booleanfalse
loading是否为加载中状态booleanfalse
loading-icon自定义加载中状态图标组件stringspinner
disabled按钮是否为禁用状态booleanfalse
icon按钮图标string-
autofocus是否自动聚焦(原生autofocus属性)booleanfalse
native-type原生 type 属性enum - 'button'| 'submit'| 'reset'button
tag自定义元素标签string/Componentbutton
use-throttle是否使用节流模式booleantrue
throttle-duration节流模式下,节流时间间隔(ms)number500

Events

NameDescriptionType
click按钮点击事件(event: MouseEvent)=> void

Slots

NameDescription
default默认插槽, 按钮内容
loading自定义加载图标

Expose

NameDescriptionType
ref按钮 html 元素Ref<HTMLButtonElement>
size按钮尺寸ComputedRef<''|'small' |'large'>
type按钮类型ComputedRef<''|'primary' |...>
disabled按钮禁用状态ComputedRef<boolean>

ButtonGroup API

Props

NameDescriptionTypeDefault
size尺寸enum - 'large'| 'default'| 'small'
type类型enum - 'primary'| 'success'| 'warning'| 'danger'| 'info'info
disabled按钮组是否为禁用状态booleanfalse

Slots

NameDescriptionSub Component
default默认插槽Button