Axios with promise.prototype.finally doesn't work

筅森魡賤 提交于 2019-12-01 20:51:44

问题


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

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

I am using Gulp with Browserify.

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();

回答1:


Try one of these see if it works:

  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.

  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. 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');



来源:https://stackoverflow.com/questions/39696007/axios-with-promise-prototype-finally-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!