
示例资源来自官网:https://www.antdv.com/components/button-cn
在 Ant Design Vue 中我们提供了五种按钮。
- 主按钮:用于主行动点,一个操作区域只能有一个主按钮。
- 默认按钮:用于没有主次之分的一组行动点。
- 虚线按钮:常用于添加操作。
- 文本按钮:用于最次级的行动点。
- 链接按钮:一般用于链接,即导航至某位置。
以及四种状态属性与上面配合使用。
- 危险:删除/移动/修改权限等危险操作,一般需要二次确认。
- 幽灵:用于背景色比较复杂的地方,常用在首页/产品页等展示场景。
- 禁用:行动点不可用的时候,一般需要文案解释。
- 加载中:用于异步操作等待反馈的时候,也可以避免多次提交。
- html>
- <html>
-
- <head>
- <meta charset="utf-8" />
- <title>title>
- head>
- <link rel="stylesheet" type="text/css" href="css/antd.min.css" />
-
- <body>
- <div id="app">
- <h1>基础按钮h1>
- <a-button type="primary">Primary Buttona-button>
- <a-button>Default Buttona-button>
- <a-button type="dashed">Dashed Buttona-button>
- <a-button type="text">Text Buttona-button>
- <a-button type="link">Link Buttona-button>
- <hr/>
- <h1>禁用-警告-图标按钮h1>
- <a-button type="primary" disabled>Primary(disabled)a-button>
- <a-button type="primary" danger>Primarya-button>
- <a-button type="primary">
- <a-icon type="wifi">a-icon>
- a-button>
- <a-button type="primary" shape="circle">
- <a-icon type="wifi">a-icon>
- a-button>
- <hr/>
- <h1>按钮组h1>
- <a-radio-group>
- <a-radio-button value="large">Largea-radio-button>
- <a-radio-button value="default">Defaulta-radio-button>
- <a-radio-button value="small">Smalla-radio-button>
- a-radio-group>
- <hr/>
- <h1>宽度按钮h1>
- <a-button type="primary" block>Primarya-button>
- <a-button block>Defaulta-button>
- <a-button type="dashed" block>Dasheda-button>
- <a-button danger block>Dangera-button>
- <a-button type="link" block>Linka-button>
- div>
- <script src="js/vue.min.js" type="text/javascript" charset="utf-8">script>
- <script src="js/antd.min.js" type="text/javascript" charset="utf-8">script>
- <script type="text/javascript">
- new Vue({
- el: "#app"
- })
- script>
- body>
-
- html>

通过设置 Button 的属性来产生不同的按钮样式,推荐顺序为:type -> shape -> size -> loading -> disabled。
按钮的属性说明如下:
| 属性 | 说明 | 类型 | 默认值 | 版本 |
|---|---|---|---|---|
| block | 将按钮宽度调整为其父宽度的选项 | boolean | false | |
| danger | 设置危险按钮 | boolean | false | 2.2.0 |
| disabled | 按钮失效状态 | boolean | false | |
| ghost | 幽灵属性,使按钮背景透明 | boolean | false | |
| href | 点击跳转的地址,指定此属性 button 的行为和 a 链接一致 | string | - | |
| htmlType | 设置 button 原生的 type 值,可选值请参考 HTML 标准 | string | button | |
| icon | 设置按钮的图标类型 | v-slot | - | |
| loading | 设置按钮载入状态 | boolean | { delay: number } | false | |
| shape | 设置按钮形状 | default | circle | round | 'default' | |
| size | 设置按钮大小 | large | middle | small | middle | |
| target | 相当于 a 链接的 target 属性,href 存在时生效 | string | - | |
| type | 设置按钮类型 | primary | ghost | dashed | link | text | default | default |
| 事件名称 | 说明 | 回调参数 | 版本 |
|---|---|---|---|
| click | 点击按钮时的回调 | (event) => void |
支持原生 button 的其他所有属性。
根据 Ant Design 设计规范要求,我们会在按钮内(文本按钮和链接按钮除外)只有两个汉字时自动添加空格,如果你不需要这个特性,可以设置 ConfigProvider的 autoInsertSpaceInButton 为 false。