问题描述
不确定我错过了什么。按照此处的说明操作:
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
.
我在浏览器中使用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:
-
看看你是否有可用于全局承诺的垫片?当browserify运行捆绑包时,在chrome控制台中输入
Promise
。如果你没有它,可以使用Babel或者使用es6或只提供Prom的lib。
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');
这篇关于Axios with promise.prototype.finally不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!