关于compass的疑问
发布于 6 年前 作者 changxiulan 9729 次浏览 来自 问答

startCom(){

    var that = this

    wx.onCompassChange(function (res) {

      console.log(res.direction)

      that.setData({directerNum:res.direction})

    })

  },

  /**

   * 生命周期函数–监听页面初次渲染完成

   */

  onReady: function () {

 

  },

  /**

   * 生命周期函数–监听页面显示

   */

  onShow: function () {

    var that = this

    wx.startCompass({

      success: function () {

        that.startCom()

      }

    })

  },

  /**

   * 生命周期函数–监听页面隐藏

   */

  onHide: function () {

  },

  /**

   * 生命周期函数–监听页面卸载

   */

  onUnload: function () {

    wx.stopCompass()

  },

先贴这样一段代码,这是由index页面navigation过来的,其中在之前我将stopCompass()写在onHide中,后来发现返回会触发的

是onUnload,这样是对的,但在之前,也就是写在onHide中,会出现这样一个问题,根本不能销毁starCompass成功触发的StartCom()

函数,测试用console.log很明显,这是因为startCompass这个是独立于page?类似于两个线程?但这样不符合其设计的想法吧,在page

里面设置的,如果没有特别说明,不是应该与其共生吗?而且这样应该会有一些漏洞?

1 回复

请问问题解决了吗,我现在就遇见了这样的问题,需要处理

回到顶部