Skip to content

Button 按钮

常用的操作按钮。

基础用法

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

<template>
  <p>
    <px-button>Button</px-button>
    <px-button type="primary">Primary</px-button>
    <px-button type="success">Success</px-button>
    <px-button type="warning">Warning</px-button>
    <px-button type="danger">Danger</px-button>
  </p>

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

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

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

禁用状态

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

<template>
  <p>
    <px-button>Button</px-button>
    <px-button type="primary">Primary</px-button>
    <px-button type="success">Success</px-button>
    <px-button type="warning">Warning</px-button>
    <px-button type="danger">Danger</px-button>
  </p>
  <p>
    <px-button disabled>Button</px-button>
    <px-button type="primary" disabled>Primary</px-button>
    <px-button type="success" disabled>Success</px-button>
    <px-button type="warning" disabled>Warning</px-button>
    <px-button type="danger" disabled>Danger</px-button>
  </p>
</template>

图标按钮

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

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

按钮组

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

<template>
  <p>
    <px-button-group type="primary" round>
      <px-button>Button1</px-button>
      <px-button>Button2</px-button>
    </px-button-group>
  </p>
  <p>
    <px-button-group type="success" round>
      <px-button>Button1</px-button>
      <px-button>Button2</px-button>
      <px-button>Button3</px-button>
    </px-button-group>
  </p>
  <p>
    <px-button-group type="warning" round>
      <px-button>Button1</px-button>
      <px-button>Button2</px-button>
      <px-button>Button3</px-button>
      <px-button>Button4</px-button>
    </px-button-group>
  </p>
  <p>
    <px-button-group type="danger">
      <px-button type="primary" icon="edit" round />
      <px-button type="primary" icon="share" />
      <px-button type="primary" icon="trash" round />
    </px-button-group>
  </p>
</template>

加载状态

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

TIP

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

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

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

按钮尺寸

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

<template>
  <p>
    <px-button type="primary" size="large">817</px-button>
    <px-button type="success" size="large">817</px-button>
    <px-button type="warning" size="large">817</px-button>
    <px-button type="danger" size="large">817</px-button>
  </p>
  <p>
    <px-button type="primary">817</px-button>
    <px-button type="success">817</px-button>
    <px-button type="warning">817</px-button>
    <px-button type="danger">817</px-button>
  </p>
  <p>
    <px-button type="primary" size="small">817</px-button>
    <px-button type="success" size="small">817</px-button>
    <px-button type="warning" size="small">817</px-button>
    <px-button type="danger" size="small">817</px-button>
  </p>
</template>

Tag

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

<template>
  <px-button>button</px-button>
  <px-button tag="div" role="button" tabindex="0">div</px-button>
  <px-button type="primary" tag="a">a</px-button>
</template>

节流模式

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

<script setup>
const handleBtnClick = () => {
  console.log('btn click')
}
</script>

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

Button API

Props

NameDescriptionTypeDefault
size尺寸enum - large | default | small
type类型enum - primary | success | warning | danger | basebase
plain是否为朴素按钮booleanfalse
round是否为圆角按钮booleanfalse
circle是否为圆形按钮booleanfalse
loading是否为加载中状态booleanfalse
loading-icon自定义加载中状态图标组件stringspinner
disabled按钮是否为禁用状态booleanfalse
icon按钮图标string-
autofocus是否自动聚焦(原生autofocus属性)booleanfalse
native-type原生 type 属性enum - button | submit | resetbutton
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<default | small | large>
type按钮类型ComputedRef<''| primary |...>
disabled按钮禁用状态ComputedRef<boolean>

ButtonGroup API

Props

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

Slots

NameDescriptionSub Component
default默认插槽Button
本站访客数 人次 本站总访问量