带有 promise.prototype.finally 的 Axios 不起作用 [英] Axios with promise.prototype.finally doesn't work

查看:39
本文介绍了带有 promise.prototype.finally 的 Axios 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定我错过了什么.按照此处的说明操作:https://github.com/mzabriskie/axios/blob/master/COOKBOOK.md

Not sure what I am missing. Following the instructions here: https://github.com/mzabriskie/axios/blob/master/COOKBOOK.md

我已经 npm 安装了 axios 和 npm install axios promise.prototype.finally --save.

I have npm installed both axios and npm install axios promise.prototype.finally --save.

我在 Browserify 中使用 Gulp.

I am using Gulp with Browserify.

var axios = require('axios');
require('promise.prototype.finally');

axios.get('http://google.com').finally(function(){
    console.log('test');
});

错误:

app-7ee90adab7.js:18780 Uncaught TypeError: axios.get(...).finally is not a function

更新:这使它起作用,但我需要这样做吗?

Update: This makes it work but do I need to do this?

var promiseFinally = require('promise.prototype.finally');
promiseFinally.shim();

推荐答案

尝试其中一种,看看是否有效:

Try one of these see if it works:

  1. 看看你是否有一个全局 Promise 可以用来填充它?当 browserify 运行 bundle 时,在 chrome 控制台中输入 Promise.如果没有,请使用 Babel 或使 es6 或仅 Promise 可用的库.

  1. See if you have a global Promise available to shim it? Enter Promise in chrome console while the browserify is running the bundle. If you don't have it, use Babel or a lib that makes es6 or just Promise available.

如果它由于某种原因不起作用……那么 axios cookbook.md 没有做对,因为您必须调用 shim() 将它应用到 promise proto 上.为什么不使用速记 require('promise.prototype.finally').shim(); 如果你不喜欢那样,否则你必须 require('es6-shim');

If it didn't work for some reason... well axios cookbook.md didn't get it right, since you have to call shim() to apply it on promise proto. why don't you use a shorthand require('promise.prototype.finally').shim(); if you don't like it that way, otherwise you have to require('es6-shim');

这篇关于带有 promise.prototype.finally 的 Axios 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆