简体   繁体   English

带有 promise.prototype.finally 的 Axios 不起作用

[英]Axios with promise.prototype.finally doesn't work

Not sure what I am missing.不知道我错过了什么。 Following the instructions here: https://github.com/mzabriskie/axios/blob/master/COOKBOOK.md按照此处的说明操作: https : //github.com/mzabriskie/axios/blob/master/COOKBOOK.md

I have npm installed both axios and npm install axios promise.prototype.finally --save .我已经 npm 安装了 axios 和npm install axios promise.prototype.finally --save

I am using Gulp with Browserify.我在 Browserify 中使用 Gulp。

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

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

Error:错误:

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. See if you have a global Promise available to shim it?看看你是否有一个全局 Promise 可以用来填充它? Enter Promise in chrome console while the browserify is running the bundle.当 browserify 运行 bundle 时,在 chrome 控制台中输入Promise If you don't have it, use Babel or a lib that makes es6 or just Promise available.如果没有,请使用 Babel 或使 es6 或仅 Promise 可用的库。

  2. 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.如果由于某种原因它不起作用......那么 axios cookbook.md 没有做对,因为你必须调用 shim() 将它应用到 promise proto 上。 why don't you use a shorthand require('promise.prototype.finally').shim();为什么不使用速记require('promise.prototype.finally').shim(); if you don't like it that way, otherwise you have to require('es6-shim');如果你不喜欢那样,否则你必须require('es6-shim');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM