收藏
回答

封装请求fetch,小程序开发环境正常,上线环境真机报错?


export default fetch = (url, data = {}, method, headers, timeout) => {

return new Promise((resolve, reject) => {

wx.getStorage({

key: 'baseUrl',

success: (res) => {

//发送请求

wx.request({

url: `${res.data}${url}`,

data: data,

method: method,

header: headers,

timeout: timeout,

success: res => {

resolve(res)

let warning = res.data.HttpMessage

if (warning == '身份验证失败,拒绝访问') {

wx.hideLoading();

wx.showModal({

title: '提示',

content: '身份验证失败,是否重新登录?',

confirmText: "确认",

cancelText: "取消",

success: (res) => {

if (res.confirm) {

wx.redirectTo({

url: 'pages/logs/logs'

});

} else if (res.cancel) {


}

}

});

}

},

fail: (err) => {

reject(err);

console.log(err)

},

complete: (res) => {

// wx.hideLoading()

}


})

}

})

})

}

不支持吗,开发正常,最近又有更新吗,上线就不行了

回答关注问题邀请回答
收藏

2 个回答

  • 疯狂的小辣椒
    疯狂的小辣椒
    2019-09-09

    可以提供appid和复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)?

    2019-09-09
    有用 1
    回复 1
    • 123
      123
      2019-09-09
      感谢关注,感谢
      2019-09-09
      回复
  • 123
    123
    2019-09-09

    已找到问题,粗心大意,删除剩6个页面(5个tabBar和一个登录页面)然后上传体验版发现依然报错,接着改fetch名称,6个页面和封装的方法“fetch”都重新命名依然同样错误,然后编辑器全局搜索fetch发现封装接口那里导出了一个没声明的fetch,解决,感谢各位大佬,是小程序让大家走到一起,谢谢小时光

    2019-09-09
    有用
    回复 2
    • 小时光
      小时光
      2019-09-10
      您好,能贴一下,现在export 以及import的代码片段吗,学习下,谢谢。
      2019-09-10
      回复
    • 123
      123
      2019-09-16回复小时光
      https://www.cytqq.com/promise-wrapper-request-wx-request/
      2019-09-16
      1
      回复
登录 后发表内容
问题标签