分享时能不能在函数中添加判断?

小程序 文章 2022-02-17 18:20 455 0 全屏看文

AI助手支持GPT4.0

分享时能不能在函数中添加判断?Can you add a judgment to the function when sharing?

分享时能不能在函数中添加判断?

在调用onShareAppMessage()时,我想在里面添加一个判断(比如用户是否登录),如果判断不通过,不希望底部弹出分享窗口,而是跳到登录页面。在测试时发现只要调用了onShareAppMessage()必定会弹出底部分享窗口

When calling onshareaappmessage(), I want to add a judgment (such as whether the user logs in). If the judgment fails, I don't want the sharing window to pop up at the bottom, but jump to the login page. During the test, it is found that as long as onshareaappmessage() is called, the bottom sharing window will pop up

回答:

超:

提前判断 根据判断结果 替换对应点击按钮

周冉:

一旦走进onShareAppMessage()你没法阻止弹出分享弹框。

要是用户未登录的话你可以把分享给禁用掉。但用户也不知道要登陆才能分享。

所以你可以在页面上自己画个分享按钮,如果未登录就弹框提示,如果已登录就用<button open-type='share'></button>来渲染

brave:
onShow(){  if (登录了) {    ....  } else {    wx.hideShareMenu({      menus: ['shareAppMessage', 'shareTimeline']    })  }}

-EOF-

AI助手支持GPT4.0