鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 微信小程序極光IM初始化init在app.js內(nèi)成功其他頁面調(diào)用JIM not

微信小程序極光IM初始化init在app.js內(nèi)成功其他頁面調(diào)用JIM not defined是為什么

圖片描述

JIM is not defined;at pages/record/record page lifeCycleMethod onLoad function
ReferenceError: JIM is not defined
 /**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (option) {
    wx.showLoading({
      title: '加載中',
      mask: true
    });

    //極光登錄
    JIM.login({
      'username': app.userIMinfo.username,
      'password': app.userIMinfo.password,
      'is_md5': true
    }).onSuccess(function (data) {
      console.log(data)
      wx.hideLoading();

      //監(jiān)聽實時會話信息
      JIM.onMsgReceive(function (data) {
        console.log(data)
        if (data.messages.length >= 1) {
          //把新信息添加到userMsg里
          let msgBox = that.data.userMsg
          msgBox = msgBox.concat(data.messages)
          that.setData({
            userMsg: msgBox
          })
          //把新得到的msgBos存到本地緩存
          wx.setStorage({
            key: option.id,
            data: msgBox
          })
        }
      });
      //監(jiān)聽離線新消息
      JIM.onSyncConversation(function (data) {
        console.log(data)
        let msgBox = that.data.userMsg
        msgBox = msgBox.concat(data.messages)
        that.setData({
          userMsg: msgBox
        })
        wx.setStorage({
          key: option.id,
          data: msgBox
        })
      });

    }).onFail(function (data) {
      console.log(data)
      wx.showToast({
        title: '請求超時',
        icon: 'fail',
        duration: 1500
      })
    })


  },
回答
編輯回答
萌小萌

其他頁面也要初始化吧

2017年5月31日 17:00