mpShare applet sharing

  1. Import uview component (omitted)
  2. View or edit mpShare.js
module.exports = {
    onLoad() {
        // 设置默认的转发参数
        uni.$u.mpShare = {
            title: '', // 默认为小程序名称
            path: '', // 默认为当前页面路径
            imageUrl: '' // 默认为当前页面的截图
        }
    },
    onShareAppMessage() {
        return uni.$u.mpShare
    },
	// #ifdef MP-WEIXIN
	onShareTimeline() {
		return this.$u.mpShare
	}
	// #endif
}

3. Open the applet sharing function in main.js

// 引入uView对小程序分享的mixin封装
let mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare);
  1. Page custom sharing title
    Customize the title in the onLoad() function of the shared page
onLoad() {
			uni.$u.mpShare.title = '天苍苍野茫茫,风吹草低见牛羊';
		},

Guess you like

Origin blog.csdn.net/m0_43584016/article/details/129948062