Skip to content

Button 按钮

常用的操作按钮。

基础用法

::: 示例

vue
<template>
  <UiButton type="primary">主要按钮</UiButton>
  <UiButton type="success">成功按钮</UiButton>
  <UiButton type="warning">警告按钮</UiButton>
  <UiButton type="danger">危险按钮</UiButton>
</template>

:::

禁用状态

::: 示例

vue
<template>
  <UiButton disabled>默认禁用</UiButton>
  <UiButton type="primary" disabled>主要禁用</UiButton>
</template>

:::

加载状态

::: 示例

vue
<template>
  <UiButton loading>加载中</UiButton>
  <UiButton type="primary" :loading="isLoading" @click="startLoading">
    点击加载
  </UiButton>
</template>

<script setup>
import { ref } from "vue";

const isLoading = ref(false);

const startLoading = () => {
  isLoading.value = true;
  setTimeout(() => {
    isLoading.value = false;
  }, 2000);
};
</script>

:::

尺寸配置

通过 ConfigProvider 可配置全局尺寸:

::: 示例

vue
<template>
  <UiConfig-provider size="large">
    <UiButton type="primary">大尺寸</UiButton>
  </UiConfig-provider>

  <UiButton type="primary">默认尺寸</UiButton>

  <UiConfig-provider size="small">
    <UiButton type="primary">小尺寸</UiButton>
  </UiConfig-provider>
</template>

:::

API

Props

参数说明类型默认值
type按钮类型'primary' | 'success' | 'warning' | 'danger'
disabled是否禁用状态booleanfalse
loading是否加载中状态booleanfalse

Events

事件名说明参数
click点击时触发(event: MouseEvent) => void