1、新建一个text.js文件,内容如下:
export default {
data() {
return {
//设置默认的分享参数
text: {
title: '分享的title',
path: '/pages/index/index',// 默认的打开地址
imageUrl: '',
desc: '',
content: ''
}
}
},
onShareAppMessage(res) {
return {
title: this.text.title,
path: this.text.path,
imageUrl: this.text.imageUrl,
desc: this.text.desc,
content: this.text.content,
success(res) {
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失败',
icon: 'none'
})
}
}
},
onShareTimeline() {},
}
2、在main.js文件中引入;
import text from 'static/text.js'//我命名为text.js
Vue.mixin(text)
引入后就可以实现“转发给朋友”和“分享到朋友圈”了。