目录

uni-app-微信小程序onShareAppMessage设置全局分享

uni-app 微信小程序onShareAppMessage设置全局分享

common/share.js下创建文件,写入简单分享代码

以下是代码中各个属性的简要说明:

  • title
    分享内容的标题。
  • path
    分享内容的链接路径。
  • imageUrl
    分享内容的图片链接。
  • desc
    分享内容的简短描述。
  • content
    分享内容的详细内容或正文。
export default {
	data() {
		return {
			//设置默认的分享参数
			share: {
				title: '',
				path: '/pages/index/index',
				// imageUrl: '',
				// desc: '111111',
				// content: '22222'
			}
		}
	},
	onShareAppMessage(res) {
		return {
			title: this.share.title,
			path: this.share.path,
			// imageUrl: this.share.imageUrl,
			// desc: this.share.desc,
			// content: this.share.content,
			success(res) {
				uni.showToast({
					title: '分享成功'
				})
			},
			fail(res) {
				uni.showToast({
					title: '分享失败',
					icon: 'none'
				})
			}
		}
	},
	onShareTimeline() {},
}
import share from './common/share.js'
Vue.mixin(share)

https://i-blog.csdnimg.cn/direct/0e2fd1eb8377452a97e5edd6bad1ce8f.png

https://i-blog.csdnimg.cn/direct/75034bcaa87141cba8016ed74866e5e9.png

https://i-blog.csdnimg.cn/direct/88d365df296144498200afbfb34d7fa9.png