急!链接如何防止重复点击造成的重复跳转?
发布于 7 年前 作者 yaoqiang 13459 次浏览 来自 问答
<navigator url="/pages/user/user?id=1">
      <view>点我</view>
</navigator>

快速点击这个链接,将会重复打开2个(或多个)页面,求解?

我尝试使用如下代码解决:

<view bindtap="handleForward" data-url="/pages/user/user?id={{buyer.id}}">
    <view>点我</view>
</view>
handleForward(event) {
        const { url, openType } = event.currentTarget.dataset;
        let forwardObj = {
            url: url,
            success() {
                app.globalData.isNavigating = false;
            }
        };
        if (!app.globalData.isNavigating) {
            app.globalData.isNavigating = true;
 
            switch (openType) {
                case 'switchTab':   // 切换tab
                    wx.switchTab(forwardObj);
                    break;
                case 'redirect':    // 重定向
                    wx.redirectTo(forwardObj);
                    break;
                default:            // 正常跳转
                    wx.navigateTo(forwardObj);
                    break;
            }
        }
    }

但是似乎__还是没有任何效果__,求解!

回到顶部