微信小程序 右上角分享 实现代码

效果

在这里插入图片描述

第一步:在data中定义变量

分享内容变量

share: {
    
    
    title: "名称",  // 分享显示名称
    path: "/pages/index/index", // 全局分享的路径,比如 首页
    imageUrl: "/static/images/logo.png", // 全局分享的图片(可本地可网络)
},

第二步:定义分享放方法

// 定义分享
// 发送给朋友
onShareAppMessage(res) {
    
    
    return {
    
    
        title: this.share.title,
        path: this.share.path,
        imageUrl: this.share.imageUrl,
    };
},
//分享到朋友圈
onShareTimeline(res) {
    
    
    return {
    
    
        title: this.share.title,
        path: this.share.path,
        imageUrl: this.share.imageUrl,
    };
},

完成如上步骤即可实现!!!

如果觉得有用欢迎点赞关注

猜你喜欢

转载自blog.csdn.net/u012551928/article/details/127844142