linwe
2024-08-08 3c738f4fe2762bba8087e5a22fc0dc06560eab0e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export default {
    data() {
        return {
            //设置默认的分享参数
            //如果页面不设置share,就触发这个默认的分享
            share: {
                title: '荆楚水库', //自定义标题
                path: `/pages/home/index`, //默认跳转首页
                imageUrl: '', //可设置默认分享图,不设置默认截取头部5:4
            }
        }
    },
    onShareAppMessage(res) { //发送给朋友
        // let that = this
        // 动态获取当前页面栈
        // let pages = getCurrentPages(); //获取所有页面栈实例列表
        // let nowPage = pages[pages.length - 1]; //当前页页面实例
        // that.share.path = `/${nowPage.route}`
        return {
            title: this.share.title,
            path: this.share.path,
            imageUrl: this.share.imageUrl,
            success(res) {
                console.log('success(res)==', res);
                uni.showToast({
                    title: '分享成功'
                })
            },
            fail(res) {
                console.log('fail(res)==', res);
                uni.showToast({
                    title: '分享失败',
                    icon: 'none'
                })
            }
        }
    },
}