modification of global variable “Promise.prototype.finally“ is not allowed when using plugins at app

使用插件后微信小程序报错信息:

[non-writable] modification of global variable “Promise.prototype.finally” is not allowed when using plugins at app.json.

解决,在封装请求的时候判断一下finally

// 无论promise对象最后状态如何都会执行
// Promise.prototype.finally = function(callback) {
//   let P = this.constructor
//   return this.then(
//     (value) => P.resolve(callback()).then(() => value),
//     (reason) =>
//       P.resolve(callback()).then(() => {
//         throw reason
//       })
//   )
// }

if (!Promise.prototype.finally) {
  Promise.prototype.finally = function(callback) {
    let P = this.constructor
    return this.then(
      (value) => P.resolve(callback()).then(() => value),
      (reason) =>
        P.resolve(callback()).then(() => {
          throw reason
        })
    )
  }
}

如果对您有所帮助,给个一键三连吧~~~Thanks♪(・ω・)ノ (✪ω✪) ᕦ(・ㅂ・)ᕤ!!!

上一篇:pytest标记跳过某些测试用例不执行


下一篇:爬虫库urllib使用(2) 处理异常