按钮组件,用于响应用户点击行为,触发相关的业务逻辑。
按钮类型
按钮的type
属性支持default
, primary
, text
, dashed
四种,分别是默认按钮、主要按钮、文本按钮、虚线按钮。
展开查看代码
vue
<template>
<j-space wrap>
<j-button>Default</j-button>
<j-button type="primary">Primary</j-button>
<j-button type="text">Text</j-button>
<j-button type="dashed">Dashed</j-button>
</j-space>
</template>
<template>
<j-space wrap>
<j-button>Default</j-button>
<j-button type="primary">Primary</j-button>
<j-button type="text">Text</j-button>
<j-button type="dashed">Dashed</j-button>
</j-space>
</template>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
轮廓按钮
通过outlined
属性支持朴素按钮风格,其背景色为透明,适合用在容器块已经有背景色的场景。
展开查看代码
vue
<template>
<j-space wrap style="padding: 10px 20px; background-color: #bec8c8">
<j-button outlined>Default</j-button>
<j-button outlined type="primary">Primary</j-button>
<j-button outlined type="dashed">Dashed</j-button>
<j-button outlined danger>Danger</j-button>
<j-button outlined type="primary" danger>Primary & Danger</j-button>
<j-button outlined disabled>Disabled</j-button>
<j-button outlined type="primary" disabled>Primary & Disabled</j-button>
<j-button outlined danger disabled>Danger & Disabled</j-button>
<j-button outlined type="primary" danger disabled>Primary & Danger & Disabled</j-button>
</j-space>
</template>
<template>
<j-space wrap style="padding: 10px 20px; background-color: #bec8c8">
<j-button outlined>Default</j-button>
<j-button outlined type="primary">Primary</j-button>
<j-button outlined type="dashed">Dashed</j-button>
<j-button outlined danger>Danger</j-button>
<j-button outlined type="primary" danger>Primary & Danger</j-button>
<j-button outlined disabled>Disabled</j-button>
<j-button outlined type="primary" disabled>Primary & Disabled</j-button>
<j-button outlined danger disabled>Danger & Disabled</j-button>
<j-button outlined type="primary" danger disabled>Primary & Danger & Disabled</j-button>
</j-space>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
按钮图标
通过icon
插槽控制按钮图标,你可以使用 JView UI 官方提供的@jview/icons
或者jview/icons-antd
图标库中的图标,也可以通过插槽自定义图标。
展开查看代码
vue
<template>
<j-space wrap>
<j-button>
<template #icon>
<Codesandbox />
</template>
Default
</j-button>
<j-button type="primary">
<template #icon>
<Codepen />
</template>
Primary
</j-button>
<j-button type="primary" loading>
<template #icon>
<Codepen />
</template>
Primary & Loading
</j-button>
<j-button type="dashed">
<template #icon>
<div
style="
width: 16px;
height: 16px;
line-height: 16px;
font-size: 12px;
color: #fff;
border-radius: 100%;
background-color: var(--vp-c-brand);
"
>
i
</div>
</template>
自定义图标
</j-button>
<j-button type="primary" danger>
<template #icon>
<CloudDownloadOutlined />
</template>
AntD 图标
</j-button>
<j-button type="primary" shape="circle">
<template #icon>
<Search />
</template>
</j-button>
<j-button type="primary" shape="round">
<template #icon>
<Search />
</template>
</j-button>
<j-button type="primary">
<template #icon>
<Search />
</template>
</j-button>
</j-space>
</template>
<script setup>
import { Codesandbox, Codepen, Search } from '@jview/icons'
import { CloudDownloadOutlined } from '@jview/icons-antd'
</script>
<template>
<j-space wrap>
<j-button>
<template #icon>
<Codesandbox />
</template>
Default
</j-button>
<j-button type="primary">
<template #icon>
<Codepen />
</template>
Primary
</j-button>
<j-button type="primary" loading>
<template #icon>
<Codepen />
</template>
Primary & Loading
</j-button>
<j-button type="dashed">
<template #icon>
<div
style="
width: 16px;
height: 16px;
line-height: 16px;
font-size: 12px;
color: #fff;
border-radius: 100%;
background-color: var(--vp-c-brand);
"
>
i
</div>
</template>
自定义图标
</j-button>
<j-button type="primary" danger>
<template #icon>
<CloudDownloadOutlined />
</template>
AntD 图标
</j-button>
<j-button type="primary" shape="circle">
<template #icon>
<Search />
</template>
</j-button>
<j-button type="primary" shape="round">
<template #icon>
<Search />
</template>
</j-button>
<j-button type="primary">
<template #icon>
<Search />
</template>
</j-button>
</j-space>
</template>
<script setup>
import { Codesandbox, Codepen, Search } from '@jview/icons'
import { CloudDownloadOutlined } from '@jview/icons-antd'
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
请一定使用icon
插槽展示图标,直接将图标放在Button
标签内虽然也能展示图标,但是无法与loading
属性协同。错误示范如下:
vue
<j-button loading>
<Search />Default
</j-button>
<j-button loading>
<Search />Default
</j-button>
1
2
3
2
3
按钮状态
- 加载中
通过loading
属性可以支持按钮加载状态,加载状态下点击按钮不会触发click
事件。
展开查看代码
vue
<template>
<j-space wrap>
<j-button type="primary" loading>加载中</j-button>
<j-button type="primary" shape="circle" loading></j-button>
<j-button type="primary" shhape="round" loading></j-button>
<j-button loading></j-button>
<j-button danger loading>Danger</j-button>
<j-button type="primary" danger loading>Primary & Danger</j-button>
</j-space>
</template>
<template>
<j-space wrap>
<j-button type="primary" loading>加载中</j-button>
<j-button type="primary" shape="circle" loading></j-button>
<j-button type="primary" shhape="round" loading></j-button>
<j-button loading></j-button>
<j-button danger loading>Danger</j-button>
<j-button type="primary" danger loading>Primary & Danger</j-button>
</j-space>
</template>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
- 禁用
通过disabled
属性可以支持按钮禁用状态。
展开查看代码
vue
<template>
<j-space wrap>
<j-button disabled>Default</j-button>
<j-button type="primary" disabled>Primary</j-button>
<j-button type="text" disabled>Text</j-button>
<j-button type="dashed" disabled>Dashed</j-button>
<j-button danger disabled>Danger</j-button>
<j-button type="primary" danger disabled>Primary & Danger</j-button>
</j-space>
</template>
<template>
<j-space wrap>
<j-button disabled>Default</j-button>
<j-button type="primary" disabled>Primary</j-button>
<j-button type="text" disabled>Text</j-button>
<j-button type="dashed" disabled>Dashed</j-button>
<j-button danger disabled>Danger</j-button>
<j-button type="primary" danger disabled>Primary & Danger</j-button>
</j-space>
</template>
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
危险状态
通过danger
属性控制危险状态,适用于一些需要谨慎操作的按钮。
展开查看代码
vue
<template>
<j-space wrap>
<j-button danger>Danger</j-button>
<j-button danger type="primary">Primary & Danger</j-button>
<j-button danger type="text">Text & Danger</j-button>
<j-button danger type="dashed">Dashed & Danger</j-button>
</j-space>
</template>
<template>
<j-space wrap>
<j-button danger>Danger</j-button>
<j-button danger type="primary">Primary & Danger</j-button>
<j-button danger type="text">Text & Danger</j-button>
<j-button danger type="dashed">Dashed & Danger</j-button>
</j-space>
</template>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
按钮尺寸 & 形状
通过size
属性控制按钮尺寸。
通过shape
属性控制按钮形状。
展开查看代码
vue
<template>
<j-space align="center" wrap>
<j-button type="primary" size="small">Small</j-button>
<j-button type="primary">Default</j-button>
<j-button type="primary" size="large">Large</j-button>
<j-button type="primary" shape="round" size="small">Small</j-button>
<j-button type="primary" shape="round">Default</j-button>
<j-button type="primary" shape="round" size="large">Large</j-button>
<j-button type="primary" shape="circle" size="small">S</j-button>
<j-button type="primary" shape="circle">D</j-button>
<j-button type="primary" shape="circle" size="large">L</j-button>
</j-space>
</template>
<template>
<j-space align="center" wrap>
<j-button type="primary" size="small">Small</j-button>
<j-button type="primary">Default</j-button>
<j-button type="primary" size="large">Large</j-button>
<j-button type="primary" shape="round" size="small">Small</j-button>
<j-button type="primary" shape="round">Default</j-button>
<j-button type="primary" shape="round" size="large">Large</j-button>
<j-button type="primary" shape="circle" size="small">S</j-button>
<j-button type="primary" shape="circle">D</j-button>
<j-button type="primary" shape="circle" size="large">L</j-button>
</j-space>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
独占一行
通过block
属性控制按钮独占一行。
展开查看代码
vue
<template>
<j-space direction="column" style="width: 300px">
<j-button block>Default</j-button>
<j-button block type="primary">Primary</j-button>
<j-button block disabled>Disabled</j-button>
<j-button block type="dashed">Dashed</j-button>
</j-space>
</template>
<template>
<j-space direction="column" style="width: 300px">
<j-button block>Default</j-button>
<j-button block type="primary">Primary</j-button>
<j-button block disabled>Disabled</j-button>
<j-button block type="dashed">Dashed</j-button>
</j-space>
</template>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
属性
参数 | 说明 | 类型 | 默认值 | 必填 |
---|---|---|---|---|
disabled | 禁用按钮 | boolean | 无 | 否 |
type | 按钮的类型 | "default" | "text" | "dashed" | "primary" | 'default' | 否 |
outlined | 轮廓按钮,背景色会变成透明 | boolean | 无 | 否 |
feedback | 是否支持按钮点击反馈效果 | boolean | true | 否 |
block | 块级按钮 | boolean | 无 | 否 |
shape | 按钮的形状 | "default" | "circle" | "round" | 'default' | 否 |
icon | 定制按钮的图标部分,请使用插槽#icon | VNode | 无 | 否 |
loading | 是否加载状态 | boolean | 无 | 否 |
size | 按钮的尺寸 | "default" | "small" | "large" | 'default' | 否 |
danger | 危险按钮 | boolean | 无 | 否 |
onClick | 点击事件回调 | (event: MouseEvent) => void | 无 | 否 |