onShareAppMessage WeChat applet

onShareAppMessage(Object object)

Monitor the behavior of the user clicking the forward button in the page (button component open-type="share") or the "forward" button in the upper right menu, and customize the forward content.
Note: Only when this event handler is defined, the upper right menu will display the "Forward" button
insert image description here
insert image description here

Page({
    
    
  onShareAppMessage() {
    
    
    const promise = new Promise(resolve => {
    
    
      setTimeout(() => {
    
    
        resolve({
    
    
          title: '自定义转发标题'
        })
      }, 2000)
    })
    return {
    
    
      title: '自定义转发标题',
      path: '/page/user?id=123',
      promise 
    }
  }
})
onShareAppMessage(res){
    
    
			var that = this
			console.log(that.goods_data)
			if(res.from==='button'){
    
    //分享按钮
				return {
    
    
					title:that.goods_data.share_title||that.goods_data.goods_name,
					// path: '',
					imageUrl:that.goods_data.share_img||that.goods_data.main_img,
					success: function (res) {
    
    
					  
					  if(res.errMsg == 'shareAppMessage:ok'){
    
    
						console.log("成功",res)
					  }
					},
					fail:function(res){
    
    
					  
					  console.log("失败",res)
					  
					}
				}
			}else{
    
    
				return {
    
    
					title:that.goods_data.share_title||that.goods_data.goods_name,
					// path: '',
					imageUrl:that.goods_data.share_img||that.goods_data.main_img,
					success: function (res) {
    
    
					  
					  if(res.errMsg == 'shareAppMessage:ok'){
    
    
						console.log("成功",res)
					  }
					},
					fail:function(res){
    
    
					  
					  console.log("失败",res)
					  
					}
				}
			}
			
		}

Guess you like

Origin blog.csdn.net/qq_46199553/article/details/128851375