tabBar不支持自定义事件
发布于 6 年前 作者 zouyan 4128 次浏览 来自 问答

比如这里的tabBar我想点击后扫描二维码

目前是在扫码页面的js这样实现的:

scan() {

    wx.scanCode({

      success: function (res) {

        if (res.result) {

          wx.request({

            url: app.globalData.Api.doubanIsbn + res.result,

            method: 'GET',

            success: function (res) {

              onfire.on('scanisbn', (args) => {

                args.context.setData({

                  info: res.data

                })

              })

              wx.navigateTo({

                url: '../scanResult/scanResult'

              })

            },

            fail: function () {

              wx.showToast({

                title: '获取图书信息失败',

                icon: 'success',

                duration: 2000

              })

            }

          })

        }

      }

    })

  },

  onShow() {

    this.scan();

  },

  onReady() {

    this.scan();

  },

  onLoad(){

    // this.scan();

  }


这样的话实际上扫码会被调用两次。如果不自定义tab栏,有没有折衷的方法实现?

1 回复

为什么 onShow 和 onReady 都调 scan ? 可以考虑使用标志位判断是否已调 scan。

回到顶部