1、建立 share.js 代码如下,用于统一设置分享参数:
import { onShareAppMessage,onShareTimeline } from '@dcloudio/uni-app';
const onShare = () => {
onShareAppMessage(() => {
return {
title:'123',
path:'/pages/loading/loading'
}
})
onShareTimeline(() => {
return {
title:'456',
path:'/pages/loading/loading'
}
});
return {onShareAppMessage,onShareTimeline}
}
export default onShare;
2、页面引用:
import onShare from '@/utils/share.js';
const {onShareAppMessage,onShareTimeline} = onShare()
就有效果啦~
// vue3 main.js import { createApp } from 'vue' import App from './App.vue' const app = createApp(App) app.mixin({ onShareAppMessage(){ // ... }, onShareTimeline(){ // ... } })