uniapp 中使用的,因为 uniapp 按钮部分平台不支持一些属性,所以自己二次封装。group-button - index.js
Component({
// 支持外部传入class
externalClasses: ['iclass'],
data: {
},
properties: {
},
methods: {
handleJoinGroup (e) {
// 外抛事件
this.triggerEvent('joinChange', e)
}
}
})
group-button - index.json
{
"component": true, // 组件必须配置
"usingComponents": {}
}
group-button - index.ttml
<button
class="iclass"
open-type="joinGroup"
group-id="xxxxxxxxx"
bindjoingroup="handleJoinGroup"
>
<slot />
button>
home - index.js
const app = getApp()
Page({
data: {
},
onLoad: function () {
console.log('Welcome to Mini Code')
},
handleJoinGroup(e) {
console.log(e.detail)
}
})
home - index.json
{
"usingComponents": {
"group-button": "../group-button/index"
}
}
group-button - index.ttml
<view class="intro">
<group-button iclass="btn" bindJoinChange="handleJoinGroup">加入粉丝群group-button>
view>