微信小程序集中开发日志 DAY 6 【分享】

上一章  微信小程序集中开发日志 DAY 5 【支付】

 

参考:https://www.cnblogs.com/wzy0526/p/8330574.html

WXML

<button n open-type='share' bindtap='onShareAppMessage'>
    <text>分享账单</text>
</button>

JS

onShareAppMessage: function () {
    let that = this;
    return {
        title: '我的账单', // 转发后 所显示的title
        path: '/pages/salary/salary', // 相对的路径
        success: (res) => { // 成功后要做的事情
            console.log(res.shareTickets[0])
            wx.getShareInfo({
                shareTicket: res.shareTickets[0],
                success: (res) => {
                    that.setData({
                        isShow: true
                    })
                console.log(that.setData.isShow)
                },
                fail: function (res) { console.log(res) },
                complete: function (res) { console.log(res) }
            })
        },
        fail: function (res) {
            // 分享失败
            console.log(res)
        }
    }
}

微信小程序集中开发日志 DAY 6 【分享】