1.新建share.js
export default {
data() {
return {
share: {
title: '',
path: '/pages/index/index',
imageUrl: '',
desc: '',
content: ''
}
}
},
onLoad() {
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
},
onShareAppMessage(res) {
return {
title: this.share.title,
path: this.share.path,
imageUrl: this.share.imageUrl,
desc: this.share.desc,
content: this.share.content,
success(res) {
uni.showToast({
title: '分享成功'
})
},
fail(res) {
uni.showToast({
title: '分享失败',
icon: 'none'
})
}
}
},
onShareTimeline: function() {
return {
title: this.share.title,
query: this.share.path,
}
}
}
2.在main.js中引入并挂载
import share from './util/share.js';
Vue.mixin(share)