When WeChat Mini Programs shares, you need to call an ajax (Promise) request, and then return an object, how to achieve Synchronize?

WeChat Mini Programs will call the onShareAppMessage method when sharing, and he will return an object as a parameter when sharing. But I need to call an ajax method before he return. How about Synchronize?

  • there is a problem with async await implementation. The code and error conclusions are as follows
onShareAppMessage: async function(res) {
    let url = await getCache({key:"WebViewUrl",trafficId:wx.getStorageSync("miniId")})
    ...
    return {
      title: title,
      path: url
    }
}
conclusion: async await can not be used. If onShareAppMessage is an async function, this method is called when sharing, but the shared event is shared by default, instead of using the parameter object of my return
  • the question now is how to get the off-duty code Synchronize to implement. The object of return cannot be written into the .then method of the request method, otherwise there will be the above problem: the method will be called, but the sharing event does not take the parameters of return.
onShareAppMessage:function(res) {
    let url;
    getCache({key:"WebViewUrl",trafficId:wx.getStorageSync("miniId")}).then(cache =>{
        url = cache
    })
    return {
      title: title,
      path: url
    }
}

try replacing the ajax request with Synchronize? Jquery can be set as follows:

  

did the landlord solve the problem? I have the same problem

Menu