我的项目vue3+uniapp
1.新建/src/utils/shareMinxin.js
import { image_url } from "@/utils/baseUrl";
let image_host = image_url;
export default {
data() {
return {
share: {
title: "分享标题",
path: "首页",
imageUrl: `分享图`,
},
};
},
// 分享到微信好友功能
onShareAppMessage(res) {
return {
title: this.share.title,
path: this.share.path,
imageUrl: this.share.imageUrl,
success(res) {
uni.showToast({
title: "分享成功",
});
},
fail(res) {
uni.showToast({
title: "分享失败",
icon: "none",
});
},
};
},
// 分享到朋友圈功能
onShareTimeline(res) {
return {
title: this.share.title,
path: this.share.path,
imageUrl: this.share.imageUrl,
success(res) {
uni.showToast({
title: "分享成功",
});
},
fail(res) {
uni.showToast({
title: "分享失败",
icon: "none",
});
},
};
},
};
2. main.js 引入
import { createSSRApp, defineAsyncComponent } from "vue";
import App from "./App.vue";
// 分享混入
import shareMixin from "./utils/shareMixin.js";
export function createApp() {
const app = createSSRApp(App);
app.mixin(shareMixin);
return {
app,
};
}
以上就是全局分享啦!!!
如有个别页面分享内容需不同,可在页面中单独设置,优先级高于全局