Skip to content

Button 按钮

该组件内部实现以 uni-app button 组件为基础,进行二次封装,主要区别在于:

  • 新增了type属性,用于设置按钮类型
  • 新增了size属性,用于设置按钮大小
  • 新增了is-ripple属性,用于设置按钮点击涟漪效果

注意

按钮开放能力与 uni-app 按钮组件保持一致,不新增任何功能。参考uni-app 按钮组件

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

html
<see-button title="默认按钮" />

设置按钮参数

按钮类型

html
<see-button title="默认按钮" />
<see-button title="主要按钮" type="primary" />
<see-button title="失败按钮" type="error" />
<see-button title="警告按钮" type="warning" />
<see-button title="成功按钮" type="success" />

镂空按钮

html
<see-button isHollow title="默认按钮" />
<see-button isHollow title="主要按钮" type="primary" />
<see-button isHollow title="失败按钮" type="error" />
<see-button isHollow title="警告按钮" type="warning" />
<see-button isHollow title="成功按钮" type="success" />

禁用按钮

html
<see-button isDisabled title="默认按钮" />
<see-button isDisabled title="主要按钮" type="primary" />
<see-button isDisabled title="失败按钮" type="error" />
<see-button isDisabled title="警告按钮" type="warning" />
<see-button isDisabled title="成功按钮" type="success" />

按钮大小

html
<see-button size="normal" title="默认大小" />
<see-button size="small" title="小型尺寸" />
<see-button size="mini" title="最小尺寸" />
<see-button size="large" title="超大尺寸" />

水波动画

html
<see-button title="默认动画" isRipple />
<see-button type="primary" size="normal" title="按钮颜色" isRipple />
<see-button size="normal" title="动画颜色" isRipple ripple-color="blue" />
<see-button
  size="large"
  title="动画时长(10000ms)"
  isRipple
  ripple-time="10000"
  ripple-color="red"
  mask-time="20000"
/>

自定义

vue
<see-button :customStyle="customStyle" title="自定义宽高" />
<see-button :radius="24" title="圆角按钮" />
<see-button
  size="large"
  title="渐变色按钮"
  textColor="#FFFFFF"
  color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
  isRipple
/>
<see-button title="自定义颜色" color="#8A4D35" textColor="#FFFFFF" isRipple />
<see-button title="传入一个view">
  <view style="width: 10px; height: 10px; border: 1px red solid" />
</see-button>
<see-button size="large">
  <text>标题以slot形式</text>
</see-button>

<script lang="ts" setup>
const customStyle = {
  width: "200px",
  height: "150px",
};
</script>
vue
<see-button :customStyle="customStyle" title="自定义宽高" />
<see-button :radius="24" title="圆角按钮" />
<see-button
  size="large"
  title="渐变色按钮"
  textColor="#FFFFFF"
  color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
  isRipple
/>
<see-button title="自定义颜色" color="#8A4D35" textColor="#FFFFFF" isRipple />
<see-button title="传入一个view">
  <view style="width: 10px; height: 10px; border: 1px red solid" />
</see-button>
<see-button size="large">
  <text>标题以slot形式</text>
</see-button>

<script>
export default {
  data() {
    return {
      customStyle: {
        width: "200px",
        height: "150px",
      };
    };
  },
};
</script>

API

Props

参数名说明类型默认值可选值平台差异
title按钮文本内容String''任意字符串-
size按钮尺寸"normal" | "large" | "small" | "mini"'normal'normallargesmallmini-
type按钮类型(预置样式)"info" | "primary" | "error" | "warning" | "success"'info'infoprimaryerrorwarningsuccess-
color自定义背景色(会覆盖 type 的默认颜色)String''任意 CSS 颜色值-
textColor文本颜色String''任意 CSS 颜色值-
isRipple是否启用水波纹点击效果Booleanfalsetruefalse-
rippleTime水波纹扩散动画时长(毫秒)Number500任意数字(建议 300–800)-
maskTime水波纹淡出遮罩时长(毫秒)Number1000任意数字(建议为 rippleTime 的 2 倍)-
rippleColor点击产生的涟漪颜色String'rgba(0,0,0,.15)'任意 CSS 颜色值-
rippleStyle涟漪的自定义 style(如透明度、动画方式等)String''任意字符串-
customStyle自定义按钮 style(整体覆盖外层 view + 内部 button)String''任意字符串-
hoverClass点击时的 hover 样式(H5 & 小程序有效)String / Null''传入自定义 class 名-
border边框开关(使用 box-shadow 模拟边框)1 | 011(有边框)、0(无边框)-
isDisabled是否禁用按钮Booleanfalsetruefalse-
radius按钮圆角(px)Number4任意数字-
isHollow是否为镂空按钮(反色按钮)Booleanfalsetruefalse-

Events

属性名说明类型默认值可选值平台差异说明
click点击按钮时触发---

基于 MIT 许可发布