ES6 `fetch is undefined`

后端 未结 8 910
太阳男子
太阳男子 2020-12-02 16:27

I\'m building a site with ES6 and Babel.

In a script file, I need to make an ajax call to a service on server. For that I\'m doing like this:

fetch(\         


        
8条回答
  •  北海茫月
    2020-12-02 17:20

    I prefer to use isomorphic-unfetch instead of isomorphic-fetch, because it is able to work like a ponyfill and not a polyfill.

    The difference is that it doesn't affect the rest of code and it is more transparent of the dependencies you have.


    Install:

    yarn add isomorphic-unfetch
    

    Usage:

    // using ES6 modules
    import fetch from 'isomorphic-unfetch';
    
    // using CommonJS modules
    var fetch = require('isomorphic-unfetch');
    

提交回复
热议问题