uniapp implements mini program page forwarding and sharing to Moments

1. With the help of the page life cycle hook onShareAppMessage (OBJECT) in uniapp, the user clicks on the upper right corner to share.
Define the onShareAppMessage processing function in js (same level as onLoad and other life cycle functions) to set the sharing information of the page.

onShareAppMessage(res) {
      if (res.from === 'button') {
           // 来自页面内分享按钮
           console.log(res.target);
       }
       return {
           title: 'xxx', //分享的名称
           path: '/pages/index/xxx?id=xx',//分享详情页面时,需要把所需参数代入
           mpId: 'xxxx', //此处配置微信小程序的AppId
       };
  },

2. Use the page life cycle hook onShareTimeline in uniapp to listen to users click on the upper right corner to forward to Moments.
Define the onShareTimeline processing function in js (same level as onLoad and other life cycle functions), and forward Moments without carrying the parameters required by the page

onShareTimeline(res) {
        return {
            title: 'xxx',
            type: 0,
            summary: '',
        };
    },

Guess you like

Origin blog.csdn.net/qq_42563079/article/details/130280221