按钮 Button
用于触发一个操作。
basic
预览代码
<script setup lang="ts"> import GeistDesign from 'geist-design' import { GIconSun, GIconMoon } from '@whouu/geist-design-icons' defineOptions({ name: 'ex-button-basic' }) const dark = () => { GeistDesign.theme.enableDark() } const light = () => { GeistDesign.theme.enableLight() } </script> <template> <div class="buttons"> <g-button @click="light" :icon="GIconSun">light</g-button> <g-button @click="dark" type="primary" :icon="GIconMoon">dark</g-button> </div> </template> <style lang="scss" scoped> .buttons > button { margin-right: 8px; margin-bottom: 8px; } </style>
type
在不同的场景中使用不同类型的按钮。
预览代码
<script setup lang="ts"> defineOptions({ name: 'ex-button-type' }) </script> <template> <div class="buttons"> <g-button disabled>Disabled</g-button> <g-button shadow>Shadow</g-button> <g-button shadow type="success">Shadow with Type</g-button> <g-button circular>Circular</g-button> </div> </template> <style lang="scss" scoped> .buttons > button { margin-right: 8px; margin-bottom: 8px; } </style>
loading
任何 Button
组件都可以添加 loading
状态,表示加载中。
预览代码
<script setup lang="ts"> defineOptions({ name: 'ex-button-loading' }) </script> <template> <g-button loading>Loading</g-button> </template>
status
预览代码
<script setup lang="ts"> defineOptions({ name: 'ex-button-status' }) </script> <template> <div class="buttons"> <g-button>Basic</g-button> <g-button type="primary">Primary</g-button> <g-button type="success">Success</g-button> <g-button type="warning">Warning</g-button> <g-button type="danger">Danger</g-button> <g-button type="abort">Abort</g-button> </div> </template> <style lang="scss" scoped> .buttons > button { margin-right: 8px; margin-bottom: 8px; } </style>
ghost
背景与边框相反的按钮。
预览代码
<script setup lang="ts"> defineOptions({ name: 'ex-button-ghost' }) </script> <template> <div class="buttons"> <g-button ghost>Basic</g-button> <g-button ghost type="primary">Primary</g-button> <g-button ghost type="success">Success</g-button> <g-button ghost type="warning">Warning</g-button> <g-button ghost type="danger">Danger</g-button> <g-button ghost type="abort">Abort</g-button> </div> </template> <style lang="scss" scoped> .buttons > button { margin-right: 8px; margin-bottom: 8px; } </style>
icon
在一些特殊状态下图标会隐藏。
预览代码
<script setup lang="ts"> import { GIconMonitor, GIconGithub, GIconDatabase } from '@whouu/geist-design-icons' defineOptions({ name: 'ex-button-icon' }) </script> <template> <div class="buttons"> <g-button size="small" :icon="GIconMonitor">Monitor</g-button> <g-button :iconRight="GIconGithub">Github</g-button> <g-button size="big" :iconRight="GIconDatabase">Database</g-button> <g-button size="huge" :icon="GIconGithub" :iconRight="GIconGithub">Huge Github</g-button> </div> </template> <style lang="scss" scoped> .buttons > button { display: block; margin-bottom: 8px; } </style>
custom icon
设置任意一个你想要的图标
预览代码
<script setup lang="ts"> import { defineAsyncComponent } from 'vue' defineOptions({ name: 'ex-button-custom-icon' }) // svg 由 vite-svg-loader 加载 const GeistDesign = defineAsyncComponent(() => import('../../assets/icon.svg')) </script> <template> <g-button :icon="GeistDesign">Custom Icon</g-button> </template>
size
不同大小的按钮。你也可以手动设置样式。
预览代码
<script setup lang="ts"> defineOptions({ name: 'ex-button-size' }) </script> <template> <div class="buttons"> <g-button size="mini">Mini</g-button> <g-button size="small">Small</g-button> <g-button>Default</g-button> <g-button size="big">Big</g-button> <g-button size="small" auto>auto width</g-button> </div> </template> <style lang="scss" scoped> .buttons > button { display: block; margin-right: 8px; margin-bottom: 8px; } </style>
Attributes
属性 | 描述 | 类型 | 推荐值 | 默认 |
---|---|---|---|---|
size | 按钮大小 | string | small / mini / medium / big / huge | medium |
type | 按钮类型 | string | primary / success / danger / warning / abort / normal | primary |
loading | 是否在加载中 | boolean | - | false |
disabled | 按钮是否禁用 | boolean | - | false |
shadow | 是否包含阴影 | boolean | - | false |
circular | 圆角更大的按钮 | boolean | - | false |
auto | 自适应宽度 | boolean | - | false |
ghost | 背景与边框反色 | boolean | - | false |
icon | 设置图标(左边) | VNode / Component | - | - |
iconRight | 设置图标(右边) | VNode / Component | - | - |
Events
事件名称 | 描述 | 回调参数 |
---|---|---|
click | 点击按钮时的回调 | (event) => void |