
//分享功能
const shareEvent = (option, obj) => {
let shareObj = {
title: obj.title,
path: obj.path,
imgUrl: obj.imgUrl,
success(res){
// 转发成功之后的回调
if (res.errMsg == 'shareAppMessage:ok') {}
},
fail(res){
// 转发失败之后的回调
if (res.errMsg == 'shareAppMessage:fail cancel') {
// 用户取消转发
} else if (res.errMsg == 'shareAppMessage:fail') {
// 转发失败,其中 detail message 为详细失败信息
}
},
complete(){
// 转发结束之后的回调(转发成不成功都会执行)
}
};
if (option.from === 'button') {
// 来自页面内转发按钮
console.log(option.target)
}
return shareObj;
}
在使用分享的页面中引入util.js
const util = require('./utils/util.js');
/**
用户点击右上角分享
*/
onShareAppMessage: function(option){
console.log(option);
let obj = {
title: '我的老窝',
path: 'pages/index/index',
imageUrl: ''
};
return util.shareEvent(option, obj);
}
备注:记得要在调用的时候使用,return。
教程来源:PHP中文网
原文链接:https://www.php.cn/xiaochengxu-409286.html
三五互联网站提供微信小程序制作神器,无需懂技术,直接套用微信小程序模板,可视化拖拽编辑,一键快速生成微信小程序。产品链接 https://www.35.com/web/sites/


