ElementPlus Button 按鈕

2021-09-07 13:57 更新

Button 按鈕

常用的操作按鈕。

基礎用法

基礎的按鈕用法。

基礎用法

使用?type?、?plain?、?round?和?circle?屬性來定義 Button 的樣式。

<template>
  <el-row>
  <el-button>默認按鈕</el-button>
  <el-button type="primary">主要按鈕</el-button>
  <el-button type="success">成功按鈕</el-button>
  <el-button type="info">信息按鈕</el-button>
  <el-button type="warning">警告按鈕</el-button>
  <el-button type="danger">危險按鈕</el-button>
</el-row>

<el-row>
  <el-button plain>樸素按鈕</el-button>
  <el-button type="primary" plain>主要按鈕</el-button>
  <el-button type="success" plain>成功按鈕</el-button>
  <el-button type="info" plain>信息按鈕</el-button>
  <el-button type="warning" plain>警告按鈕</el-button>
  <el-button type="danger" plain>危險按鈕</el-button>
</el-row>

<el-row>
  <el-button round>圓角按鈕</el-button>
  <el-button type="primary" round>主要按鈕</el-button>
  <el-button type="success" round>成功按鈕</el-button>
  <el-button type="info" round>信息按鈕</el-button>
  <el-button type="warning" round>警告按鈕</el-button>
  <el-button type="danger" round>危險按鈕</el-button>
</el-row>

<el-row>
  <el-button icon="el-icon-search" circle></el-button>
  <el-button type="primary" icon="el-icon-edit" circle></el-button>
  <el-button type="success" icon="el-icon-check" circle></el-button>
  <el-button type="info" icon="el-icon-message" circle></el-button>
  <el-button type="warning" icon="el-icon-star-off" circle></el-button>
  <el-button type="danger" icon="el-icon-delete" circle></el-button>
</el-row>
</template>

禁用狀態(tài)

按鈕不可用狀態(tài)。

按鈕不可用狀態(tài)。

你可以使用disabled屬性來定義按鈕是否可用,它接受一個Boolean值。

<template>
  <el-row>
  <el-button disabled>默認按鈕</el-button>
  <el-button type="primary" disabled>主要按鈕</el-button>
  <el-button type="success" disabled>成功按鈕</el-button>
  <el-button type="info" disabled>信息按鈕</el-button>
  <el-button type="warning" disabled>警告按鈕</el-button>
  <el-button type="danger" disabled>危險按鈕</el-button>
</el-row>

<el-row>
  <el-button plain disabled>樸素按鈕</el-button>
  <el-button type="primary" plain disabled>主要按鈕</el-button>
  <el-button type="success" plain disabled>成功按鈕</el-button>
  <el-button type="info" plain disabled>信息按鈕</el-button>
  <el-button type="warning" plain disabled>警告按鈕</el-button>
  <el-button type="danger" plain disabled>危險按鈕</el-button>
</el-row>
</template>

文字按鈕

沒有邊框和背景色的按鈕。

文字按鈕

<template>
  <el-button type="text">文字按鈕</el-button>
<el-button type="text" disabled>文字按鈕</el-button>
</template>

圖標按鈕

帶圖標的按鈕可增強辨識度(有文字)或節(jié)省空間(無文字)。

圖標按鈕

設置?icon?屬性即可,icon 的列表可以參考 Element Plus 的 icon 組件,也可以設置在文字右邊的 icon ,只要使用?i?標簽即可,可以使用自定義圖標。

<template>
  <el-button type="primary" icon="el-icon-edit"></el-button>
<el-button type="primary" icon="el-icon-share"></el-button>
<el-button type="primary" icon="el-icon-delete"></el-button>
<el-button type="primary" icon="el-icon-search">搜索</el-button>
<el-button type="primary"
  >上傳<i class="el-icon-upload el-icon--right"></i
></el-button>
</template>

按鈕組

以按鈕組的方式出現(xiàn),常用于多項類似操作。

按鈕組

使用<el-button-group>標簽來嵌套你的按鈕。

<template>
  <el-button-group>
  <el-button type="primary" icon="el-icon-arrow-left">上一頁</el-button>
  <el-button type="primary"
    >下一頁<i class="el-icon-arrow-right el-icon--right"></i
  ></el-button>
</el-button-group>
<el-button-group>
  <el-button type="primary" icon="el-icon-edit"></el-button>
  <el-button type="primary" icon="el-icon-share"></el-button>
  <el-button type="primary" icon="el-icon-delete"></el-button>
</el-button-group>
</template>

加載中

點擊按鈕后進行數(shù)據(jù)加載操作,在按鈕上顯示加載狀態(tài)。

加載中

要設置為 loading 狀態(tài),只要設置?loading?屬性為?true?即可。

<template>
  <el-button type="primary" :loading="true">加載中</el-button>
</template>

不同尺寸

Button 組件提供除了默認值以外的三種尺寸,可以在不同場景下選擇合適的按鈕尺寸。

不同尺寸

額外的尺寸:?medium?、?small?、?mini?,通過設置?size?屬性來配置它們。

<template>
  <el-row>
  <el-button>默認按鈕</el-button>
  <el-button size="medium">中等按鈕</el-button>
  <el-button size="small">小型按鈕</el-button>
  <el-button size="mini">超小按鈕</el-button>
</el-row>
<el-row>
  <el-button round>默認按鈕</el-button>
  <el-button size="medium" round>中等按鈕</el-button>
  <el-button size="small" round>小型按鈕</el-button>
  <el-button size="mini" round>超小按鈕</el-button>
</el-row>
<el-row>
  <el-button icon="el-icon-search" circle></el-button>
  <el-button icon="el-icon-search" size="medium" circle></el-button>
  <el-button icon="el-icon-search" size="small" circle></el-button>
  <el-button icon="el-icon-search" size="mini" circle></el-button>
</el-row>
</template>

Button Attributes

參數(shù)說明類型可選值默認值
size尺寸stringmedium / small / mini
type類型stringprimary / success / warning / danger / info / text
plain是否樸素按鈕booleanfalse
round是否圓角按鈕booleanfalse
circle是否圓形按鈕booleanfalse
loading是否加載中狀態(tài)booleanfalse
disabled是否禁用狀態(tài)booleanfalse
icon圖標類名string
autofocus是否默認聚焦booleanfalse
native-type原生 type 屬性stringbutton / submit / resetbutton

Button-Group Attributes

參數(shù)說明類型可選值默認值
size用于控制該按鈕組內按鈕的尺寸stringmedium / small / mini

Button-Group Slots

NameDescription
default自定義按鈕組內容


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號