onShareAppMessage同一页面分享内容不同,如何操作?
发布于 4 年前 作者 xia71 12261 次浏览 来自 官方Issues

同一个页面分享不同的需要用户助力的资料信息,并且需要根据接口返回的助力id判断是否已经发起助力,但是使用button中的open-type=‘share’ 中绑定接口事件,发现onShareAppMessage中无法获取接口返回的id,查询资料onShareAppMessage的触发时间是最快的,所以无法获取。请问有什么办法解决吗??

2 回复

<button open-type=‘share’ data-type="{{type}}"></button>

yourFunc: function(e){

    // type用于区分获取不同的用户助力的资料信息

    var type = e.target.dataset.type

    return new Promise((resolve, reject)=>{

        wx.request({

            //…

            success: function(res){

                resolve(res.data)

            },

            fail: function(res){

                reject(res)

            }

        })

    })

},

onShareAppMessage: async function(e){

    var info = await this.yourFunc(e)

    return {

        title:’…’,

        imageUrl:’…’,

        path: ‘/pages/xxxx/xxx?id=’+info.id

    }

}

button 绑定事件fun,fun中将值放入this.formid中;onShareAppMessage 中

return {
title:'...',

imageUrl:'...',

path: '/pages/customer/index?formid='+this.formid

}

fun 中不能去请求然后设置给this,需要提前获取

回到顶部