好友分享onShareAppMessage/朋友圈分享 onShareTimeline、#ifdef 爪膊、#endif是uni-app語法判斷
返回一個(gè)Object對(duì)象 返回的具體參數(shù)可以看unn-app官方文檔
- 示例代碼
data() {
return {
//設(shè)置默認(rèn)的分享參數(shù)
// #ifdef MP-WEIXIN
share: {
title: '藍(lán)宇水泵', // 分享標(biāo)題
path: '/pages/projectList/projectList', //頁面 path 助泽,必須是以 / 開頭的完整路徑
imageUrl: '', // 分享的圖標(biāo)路徑
desc: '', // 自定義分享描述
content: '' // 分享的文案
}
// #endif
}
},
// #ifdef MP-WEIXIN
onShareAppMessage(res) {
return {
...this.share,
success(res) {
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失敗',
icon: 'none'
})
}
}
},
onShareTimeline() {
return {
...this.share,
success(res) {
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失敗',
icon: 'none'
})
}
}
}
// #endif
我設(shè)置的是全局分享顾瞻,所以會(huì)在mian.js文件膊存,局部分享只需在當(dāng)前文件使用即可
import mixin from '@/utils/mixin.js'
Vue.mixin(mixin)