1.在mixin文件夹中创建一个 share.js文件
export default {
data() {
return {
// 默认的全局分享内容
share: {
title: '',
path: '', // 全局分享的路径
imageUrl: '', // 全局分享的图片
desc: ''
}
}
},
// 定义全局分享
// 1.发送给朋友
onShareAppMessage(res) {
return {
title: this.share.title,
path: this.share.path,
desc: this.share.desc,
imageUrl: this.share.imageUrl,
}
},
//2.分享到朋友圈
onShareTimeline(res) {
return {
title: this.share.title,
path: this.share.path,
desc: this.share.desc,
imageUrl: this.share.imageUrl,
}
},
}
2.在main.js文件中引入
// 引入uView对小程序分享的mixin封装
const mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js')
Vue.mixin(mpShare)
然后就可以在小程序右上角...里进行分享
3.自定义按钮
//只能在button里面 用open-type进行分享
<u-button open-type="share">
<u-icon name="share" color="#2979ff" size="28" plain="true"></u-icon>
分享
</u-button>
然后就是自定义按钮我只能用open-type进行好友分享,朋友圈没搞明白,望大佬指教