公共组件做到兼容不同的页面

【需求】点击分享按钮,首先判断用户是否登录状态,若不登录不能进行分享,跳到APP登录页面;若登录,可弹出分享蒙层。

【步骤】1、判断登录方法并不难,由于我们APP端将登录userId存放在cookie中,只要从里面取userId即可。

    2、调APP中的分享,由于右上角的分享APP是调我们组件中的方法,(这意味着要修改组件,所以我改起来,很心虚啊,生怕会影响其它活动页面的功能),有一种方法可以很好的做到兼容,通过indexOf匹配到你要判断登录的页面,eg:匹配inviteindex.html ,就?了,

【知识点】window.location、indexOf

【代码】

            shareselect() {
                const location = window.location.href;
                if (location.indexOf('inviteindex.html') > 1 || location.indexOf('inviteaward.html') > 1) {
                    const userId = Cookie.get('userId');
                    if (!userId || userId === 'undefined' || userId === 'null') {
                        openPage('OpenPage', '', 'F00000', 'https://m.geinihua.com?GNH_EVE_Jump=');
                    } else {
                        this.mask();
                    }
                } else {
                    this.mask();
                }
            },

 

转载于:https://www.cnblogs.com/xiaoli52qd/p/7307187.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值