启动了增强编译,在开发者工具上 Promise.finally 方法不报错?
发布于 5 年前 作者 gshen 9851 次浏览 来自 官方Issues

代码片段: https://developers.weixin.qq.com/s/4Voj78mf7cbz

const app = getApp()
 
Page({
  data: {
 
  },
  onLoad: function () {
    Promise.resolve('foo')
      .then((res) => console.log(res))
      .finally(() => console.log(123));
  },
})

开发者工具能正常执行

编译后上传预览还是报错。开发运行结果,和真机运行结果还不一致?

2 回复

试了下安卓可以。。ios不行。。

const app = getApp()

Promise.prototype.finally = function (cb) {

let P = this.constructor;

return this.then(

value => P.resolve(cb()).then(() => value)

);

};

Page({

data: {

},

onLoad: function () {

Promise.resolve(‘foo’)

.then((res) => console.log(res))

.finally(() => console.log(123));

},

})

回到顶部