ES6 `fetch is undefined`

后端 未结 8 916
太阳男子
太阳男子 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:03

    Just went through this last night. In the end, after trying all sorts of things, the solution was fairly simple:

    fetch('url').then(
    response => response.json()
    ).then(
    supervisoryItem => doSomething(supervisoryItem)
    )
    

    became

    window.fetch('url').then(
    response => response.json()
    ).then(
    supervisoryItem => doSomething(supervisoryItem)
    )
    

    TL;DR fetch(stuff) should be window.fetch(stuff) EDIT This worked for me on Chrome

提交回复
热议问题