TypeError: Cannot read property 'split' of undefined 微信小程序字符串方法undefined 微信小程序踩

738 阅读1分钟

如下图

XCX2.png

代码

 onLoad(options) {
  
     var rs = options.q.split('%3D')//这里需要获取客户进入小程序的二维码网址链接
  },

xcx1.png

解决办法:加个判断条件

//如果是扫描二维码进来的,则获取网站url
 if (options.q) {
      var rs = options.q.split('D')
      console.log(rs);
      this.data.id = rs[1];
      console.log('本地存储ID');
      wx.setStorageSync('id', this.data.id);
      // wx.setStorageSync('id', '0010101');
      this.getMiniInfo();
    }