效果图
功能描述:可在任意页面进行分享小程序。
1、封装一个share.js
// share.js
export default {
// 页面初始化时执行(设置分享配置和权限)
onLoad() {
// 1. 全局默认分享配置
this.shareConfig = {
title: '城信科技',
path: '/pages/index/index', //页面路径
imageUrl: '/static/logoIcon.png' //图标
};
},
// 3. 分享给好友
onShareAppMessage() {
return this.shareConfig;
},
// 4. 分享到朋友圈(仅微信小程序)
// #ifdef MP-WEIXIN
onShareTimeline() {
return {
title: this.shareConfig.title,
query: this.shareConfig.path.split('?')[1] || '', // 提取路径参数
imageUrl: this.shareConfig.imageUrl
};
}
// #endif
};
在main.js中引入
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import {
createSSRApp
} from 'vue'
import shareMixin from '@/components/share.js';
export function createApp() {
const app = createSSRApp(App);
app.mixin(shareMixin);
return {
app
}
}
// #endif