1.使用vue混入,创建一个js文件
export default{
data(){
return {
share:{
title:'wade', // 分享页面标题
path:'/pages/login/login', // 分享页面的路径
imageUrl:'',
desc:'',
content:''
}
}
},
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'
})
}
}
}
}
2.在main.js中 全局使用
import share from './utils/share.js'
Vue.mixin(share)
3.这时已经可以实现页面分享了;可以单独在每个页面data中设置不同的分享参数
export default {
data(){
return {
//单独设置分享参数
share:{
title:'james',
path:'/pages/index/index',
imageUrl:'',
desc:'',
content:''
}
}
}
},