Skip to content

Button 按钮

响应式、高质感按钮组件,支持黑白熊猫风与 OLED 暗黑模式自动响应,包含类型、尺寸、形状、加载状态与弥散发光等全量配置。

代码示例

1. 基础按钮类型 (Type)

使用 type 属性控制按钮的主要语义形态,包含 primarysuccesswarningerrorinfodefault

vue
<template>
  <mu-button type="primary">主要按钮 Primary</mu-button>
  <mu-button type="success">成功按钮 Success</mu-button>
  <mu-button type="warning">警告按钮 Warning</mu-button>
  <mu-button type="error">危险按钮 Error</mu-button>
  <mu-button type="info">信息按钮 Info</mu-button>
  <mu-button type="default">默认按钮 Default</mu-button>
</template>

2. 风格与样式 (Style)

支持 plain 朴素边框模式、text 纯文本模式与 glow 弥散发光外晕模式。

vue
<template>
  <mu-button type="primary" plain>朴素主要 Plain</mu-button>
  <mu-button type="success" plain>朴素成功 Plain</mu-button>
  <mu-button type="primary" text>纯文本 Text</mu-button>
  <mu-button type="error" text>危险文本 Text</mu-button>
  <mu-button type="primary" glow>弥散发光 Glow</mu-button>
</template>

3. 尺寸规格 (Size)

支持 large (48px)、normal (40px)、small (32px)、mini (24px) 四种尺寸规范。

vue
<template>
  <mu-button size="large" type="primary">Large 48px</mu-button>
  <mu-button size="normal" type="primary">Normal 40px</mu-button>
  <mu-button size="small" type="primary">Small 32px</mu-button>
  <mu-button size="mini" type="primary">Mini 24px</mu-button>
</template>

4. 形状形态 (Shape)

支持 radius (微圆角)、round (全圆胶囊) 与 square (直角)。

vue
<template>
  <mu-button shape="radius" type="primary">微圆角 Radius</mu-button>
  <mu-button shape="round" type="primary">胶囊按钮 Round</mu-button>
  <mu-button shape="square" type="primary">直角按钮 Square</mu-button>
</template>

5. 状态与加载 (Status)

设置 loading 属性显示加载旋转圈,设置 disabled 禁用触发。

vue
<template>
  <mu-button loading type="primary">加载中 Loading</mu-button>
  <mu-button loading loading-text="保存中..." type="success">带文案加载</mu-button>
  <mu-button disabled type="primary">禁用主要 Disabled</mu-button>
</template>

6. 通栏与矢量图标 (Block & Icon)

设置 block 属性为独占一行宽度的通栏块级按钮,设置 icon 属性展示前置图标。

vue
<template>
  <mu-button block type="primary" icon="send">通栏发送按钮 Block Icon</mu-button>
  <mu-button block plain type="primary" icon="download">下载配置文件 Download</mu-button>
</template>

7. 自定义渐变按钮 (Gradient)

设置 type="gradient" 使用经典炫彩渐变,或通过 gradient 属性传入双色数组 (如 ['#FF416C', '#FF4B2B']) 来自定义渐变。

vue
<template>
  <mu-button type="gradient">默认渐变 Gradient</mu-button>
  <mu-button :gradient="['#FF416C', '#FF4B2B']">日落炫彩渐变</mu-button>
  <mu-button :gradient="['#8A2387', '#E94057']">魅紫浪漫渐变</mu-button>
</template>

8. 小程序开放能力 (OpenType)

通过 open-type 属性即可无缝调起微信/QQ/支付宝小程序的原生开放能力,包括获取用户信息、手机号授权、隐私授权、客服会话、消息分享、打开授权设置等。

vue
<template>
  <!-- 获取用户信息 -->
  <mu-button type="primary" icon="user" open-type="getUserInfo" @getuserinfo="onGetUserInfo">
    获取用户信息
  </mu-button>

  <!-- 获取手机号 -->
  <mu-button type="success" icon="phone" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
    手机号快捷登录
  </mu-button>

  <!-- 打开客服会话 -->
  <mu-button type="warning" icon="message" open-type="contact" @contact="onContact">
    联系在线客服
  </mu-button>

  <!-- 原生分享 -->
  <mu-button type="info" icon="share" open-type="share">
    分享给好友
  </mu-button>

  <!-- 打开授权设置 -->
  <mu-button type="default" icon="setting" open-type="openSetting">
    权限管理
  </mu-button>
</template>

<script setup>
const onGetUserInfo = (e) => {
  console.log('用户信息:', e.detail)
}
const onGetPhoneNumber = (e) => {
  console.log('手机号凭证:', e.detail)
}
const onContact = (e) => {
  console.log('进入客服会话')
}
</script>

API 属性说明 (Props)

参数名说明类型可选值默认值
type按钮类型Stringprimary / success / warning / error / gradient / info / default'primary'
gradient自定义渐变配色(双色数组或 CSS 渐变字符串)String / Array-''
size尺寸大小Stringlarge / medium / small / mini'medium'
shape形状样式Stringradius / round / square'radius'
plain是否为朴素边框模式Booleantrue / falsefalse
text是否为纯文字模式Booleantrue / falsefalse
ghost是否为幽灵透明背景模式(白色边框+文字)Booleantrue / falsefalse
dashed是否为虚线边框模式Booleantrue / falsefalse
glow是否开启弥散发光外晕Booleantrue / falsetrue
block是否为块级独占一行Booleantrue / falsefalse
bold是否加粗按钮文字Booleantrue / falsetrue
loading是否显示加载状态Booleantrue / falsefalse
loadingText加载状态文案String-''
disabled是否禁用Booleantrue / falsefalse
icon矢量图标名称String-''
iconColor图标颜色(默认跟随文字色)String-''
iconSize图标尺寸Number / String-0(自适应)
iconPosition图标位置Stringleft / right'left'
showArrow是否在按钮右侧显示内嵌箭头Booleantrue / falsefalse
width自定义按钮宽度(支持 rpx/px/% 等单位)String-''
height自定义按钮高度(支持 rpx/px 等单位)String-''
margin外边距(CSS margin 语法)String-''
padding内边距(CSS padding 语法)String-''
background自定义背景颜色String-''
color自定义文字颜色String-''
formType原生 button 的 form-type 属性Stringsubmit / reset''
openType小程序开放能力类型StringgetUserInfo / getPhoneNumber / getRealtimePhoneNumber / agreePrivacyAuthorization / contact / share / launchApp / openSetting / feedback / chooseAvatar''
lang返回用户信息的语言Stringzh_CN / zh_TW / en'zh_CN'
sessionFrom客服会话来源标识String-''
sendMessageTitle客服消息卡片标题String-''
sendMessagePath客服消息卡片路径String-''
sendMessageImg客服消息卡片图片String-''
showMessageCard是否在客服会话中展示卡片Booleantrue / falsefalse
appParameter打开 APP 时传递的参数String-''

事件说明 (Events)

事件名说明回调参数
click点击按钮时触发(非 disabled 和非 loading 状态下)(event: Event)
getuserinfo用户点击同意获取用户信息回调(event: Event)
getphonenumber获取手机号回调(event: Event)
getrealtimephonenumber实时手机号验证回调(event: Event)
agreeprivacyauthorization用户同意隐私协议回调(event: Event)
contact客服会话回调(event: Event)
error开放能力触发失败回调(event: Event)
opensetting打开设置界面完成回调(event: Event)
launchapp打开 APP 回调(event: Event)
chooseavatar获取用户头像回调(event: Event)

基于 MIT 协议开源发行

H5 模拟器 (button)🔄