uniapp 小程式分享好友和朋友圈
阿新 • • 發佈:2021-01-14
export default { data() { return { //這個share可以在每個頁面的data中設定相應的轉發內容 share: { title: '分享有禮', path: '/pages/index/index', } } }, onShareAppMessage(res) { var userId = uni.getStorageSync('shareUserId'); if (userId) this.share.path = '/pages/index/index?parentId=' + parseInt(userId); console.log(this.share.path) return { title: this.share.title, path: this.share.path, success(res) { uni.showToast({ title: '分享成功' }) }, fail(res) { uni.showToast({ title: '分享失敗', icon: 'none' }) } } }, onShareTimeline(res) { var parent_Id = 0; var userId = uni.getStorageSync('shareUserId'); if (userId) parent_Id = parseInt(userId); console.log(this.share.path) return { title: this.share.title, query: 'parentId='+parent_Id } } }
1.儲存檔案share.js
2.在main.js中全域性引用
// #ifdef MP-WEIXIN
import share from '@/share.js';
Vue.mixin(share)
// #endif