fetch not defined in Safari (ReferenceError: Can't find variable: fetch)

前端 未结 2 1963
无人及你
无人及你 2021-02-01 05:03

For some reason fetch (https://fetch.spec.whatwg.org/) is not defined in Safari (Version 9.0.3), does anyone know why? It seems to be the standard and works fine in

相关标签:
2条回答
  • 2021-02-01 05:39

    You can use https://github.com/github/fetch polyfill for unsupported browsers.

    npm install whatwg-fetch --save; 
    

    Edit: (per the comments)

    add

    import 'whatwg-fetch'; 
    

    in each file before using fetch – oliviergg

    0 讨论(0)
  • 2021-02-01 05:51

    Use whatwg-fetch polyfill. If you use webpack, you could just add it to entry point

    entry: {
      app: ['whatwg-fetch', 'your-index.js']
    }
    
    0 讨论(0)
提交回复
热议问题