Taro.request 返回的Promise 如何实现finally呢
哦哦 知道了
怎么实现的 @sfuser001
@sfuser001 怎么解决?
@sfuser001 怎么解决?
这样,随便写一个文件,例如:promise.js
内容如下:
Promise.prototype.finally = function (callback) {
let P = this.constructor;
return this.then(
value => P.resolve(callback && callback()).then(() => value),
reason => P.resolve(callback && callback()).then(() => { throw reason })
);
};
在app.js中引入
import 'promise.js';
然后,如果你要是使用的ts的话,请在 tsconfig.json中 把compilerOptions中的target 修改成 es2018
额 这个就是我 我另外一个账号忘记了😓
@chenkefeng 没有用ts,不知道能不能通过babel配置来实现。
@chenkefeng 没有用ts,不知道能不能通过babel配置来实现。
不用ts上边的方法也行。直接引入 promise.js就好了
内容如下:
Promise.prototype.finally = function (callback) { let P = this.constructor; return this.then( value => P.resolve(callback && callback()).then(() => value), reason => P.resolve(callback && callback()).then(() => { throw reason }) ); };
@chenkefeng 没有用ts,不知道能不能通过babel配置来实现。
不用ts上边的方法也行。直接引入 promise.js就好了 内容如下:
Promise.prototype.finally = function (callback) { let P = this.constructor; return this.then( value => P.resolve(callback && callback()).then(() => value), reason => P.resolve(callback && callback()).then(() => { throw reason }) ); };
我还是觉得babel能解决这个问题