n-button 按钮
view 为根承载内容与样式,内嵌原生 button 仅作能力承接层(form-type / open-type 及其事件)。文字走 text 或默认插槽;图标放插槽里配合 n-icon,纯图标按钮加 icon-only 获得正方形。
- 禁用 / 加载中会拦截点击、表单提交与微信开放能力(不只是视觉禁用)
open-type及其参数、事件仅微信小程序端生效,其它端编译时裁掉,不产生告警
平台兼容性
| App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 头条小程序 | QQ小程序 |
|---|---|---|---|---|---|---|
| √ | √ | √ | × | × | × | × |
API
属性
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|---|---|---|---|---|
| text | 按钮文字(便捷写法,内容复杂时改用默认插槽) | String | "" | - |
| aria-label | Web 可访问名称;纯图标按钮应填写,空值使用 text 或插槽文本 | String | "" | - |
| type | 按钮类型;text = 文字型(透明底无边框,文字取品牌色) | String | default | default<br/>primary<br/>success<br/>warning<br/>error<br/>info<br/>text |
| size | 按钮尺寸 | String | normal | large<br/>normal<br/>small<br/>mini |
| shape | 形状:square 小圆角 / circle 全圆角(icon-only 下即正圆) | String | square | square<br/>circle |
| plain | 镂空:背景透明,边框与文字取主题色 | Boolean | false | - |
| hairline | 细边框 0.5px(仅镂空模式生效;Android 及非高分屏取整为 1px,视觉无差异) | Boolean | true | - |
| block | 块级:宽度撑满父容器 | Boolean | false | - |
| disabled | 禁用(保色降透明,拦截点击、表单提交与开放能力) | Boolean | false | - |
| icon-only | 纯图标形态:插槽图标常驻,文字与 loadingText 不显示,loading 时加载圈套在图标外圈转;不要与 text 同用 | Boolean | false | - |
| loading | 加载中(显示加载圈,拦截点击、表单提交与开放能力) | Boolean | false | - |
| loading-text | 加载中替换文字;留空保留原文字,无内容时用内置多语言文案 | String | "" | - |
| color | 自定义颜色,支持 linear-gradient;渐变仅作用于背景(默认/填充型),type=text 与镂空的前景只接受实色,传渐变静默回落类色 | String | "" | 与 css 相同 |
| custom-class | 挂到根节点的额外 class(类需定义在组件样式表内) | String | "" | - |
| custom-style | 根节点行内样式 | String | "" | 与 css 相同 |
| text-style | 微调文字的行内样式;加下划线用 "text-decoration-line:underline"(勿用 text-decoration 简写,App 端不支持且不继承) | String | "" | 与 css 相同 |
| spinner-style | 微调加载圈的行内样式,如 "width:10px;height:10px" | String | "" | 与 css 相同 |
| throttle-time | 点击节流(毫秒),0 为不节流 | Number | 0 | - |
| hover-class | 按压时切换的 class(需是组件内已定义的类) | String | n-button--hover | - |
| open-type | 微信小程序开放能力,同原生 button open-type(仅微信端生效) | String | "" | contact<br/>share<br/>getPhoneNumber<br/>getRealtimePhoneNumber<br/>getUserInfo<br/>launchApp<br/>openSetting<br/>chooseAvatar<br/>agreePrivacyAuthorization<br/>feedback<br/>liveActivity |
| form-type | 表单类型,需置于 form 内;禁用/加载中自动失效 | String | "" | submit<br/>reset |
| app-parameter | open-type=launchApp 时向 APP 传递的参数(仅微信端) | String | "" | - |
| lang | open-type=contact 会话语言 | String | zh_CN | en<br/>zh_CN<br/>zh_TW |
| session-from | open-type=contact 会话来源 | String | "" | - |
| send-message-title | open-type=contact 会话内消息卡片标题 | String | "" | - |
| send-message-path | open-type=contact 会话内消息卡片点击跳转路径 | String | "" | - |
| send-message-img | open-type=contact 会话内消息卡片图片 | String | "" | - |
| show-message-card | 显示 open-type=contact 会话内消息卡片 | Boolean | false | - |
| phone-number-no-quota-toast | open-type=getPhoneNumber 失败时是否弹出 toast | Boolean | false | - |
事件
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| click | 点击按钮时触发(禁用/加载中不触发) | 事件对象 |
| getuserinfo | open-type=getUserInfo 时触发(微信小程序) | 事件对象 |
| contact | open-type=contact 客服会话回调(微信小程序) | 事件对象 |
| getphonenumber | open-type=getPhoneNumber 时触发(微信小程序) | 事件对象 |
| getrealtimephonenumber | open-type=getRealtimePhoneNumber 时触发(微信小程序) | 事件对象 |
| error | 开放能力发生错误时触发(微信小程序) | 事件对象 |
| opensetting | open-type=openSetting 授权页关闭后触发(微信小程序) | 事件对象 |
| launchapp | open-type=launchApp 打开 APP 成功后触发(微信小程序) | 事件对象 |
| chooseavatar | open-type=chooseAvatar 时触发(微信小程序) | 事件对象 |
| agreeprivacyauthorization | 用户同意隐私协议时触发(微信小程序) | 事件对象 |
| createliveactivity | open-type=liveActivity 订阅回调时触发(微信小程序) | 事件对象 |
插槽
| 插槽名 | 说明 |
|---|---|
| default | 按钮内容(图标与文字自由组合);纯图标形态配合 icon-only |