Javascript Reactjs API错误';TypeError:fetch(…).then(…).then(…).done不是函数';

Javascript Reactjs API错误';TypeError:fetch(…).then(…).then(…).done不是函数';,javascript,reactjs,react-native,Javascript,Reactjs,React Native,loggingIn()是我的onClick侦听器 loggingIn(){ fetch("http://sampleurl.com", { method: "POST", headers: { 'Accept': 'application/json', 'Content-Type': 'application/json'

loggingIn()是我的onClick侦听器

loggingIn(){
            fetch("http://sampleurl.com", {
                method: "POST",
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    username: this.state.username,
                    password: this.state.password,
                })
            })
                .then((response) => response.json())
        .then((responseData) => {
                console.log(responseData);
            if (responseData.response === 1) {
              alert("Success");

            } else {
                alert("Username or password is incorrect");
            }

        })
        .done();
    }
有人知道我为什么会出错吗?。当我使用这个代码来react native时,它工作得很好,但是当我将它集成到reactjs中时,它会给我这个错误

`TypeError: fetch(...).then(...).then(...).done is not a function`
fetch()返回一个承诺,在这个承诺上,您可以调用then()来获取响应,并调用catch()来获取抛出的任何错误

.done()
替换为类似
.catch((错误)=>console.error(错误))

有关详细信息,请参见此处:

fetch()返回一个承诺,您可以在该承诺上调用then()来获取响应,并调用catch()来获取抛出的任何错误

.done()
替换为类似
.catch((错误)=>console.error(错误))


有关详细信息,请参见此处:

该问题是由于捕捉块缺失引起的。我的问题在添加捕捉块后得到解决

 fetch(URL, config)
                .then(response => response.json())
                .then((data) => {})
                .catch((error) => {
                    console.log(error);
                });

该问题是由于挡块缺失造成的。我的问题在添加捕捉块后得到解决

 fetch(URL, config)
                .then(response => response.json())
                .then((data) => {})
                .catch((error) => {
                    console.log(error);
                });

删除
.done()
。删除
.done()
…但是他说上面的代码在React-Native中工作得很好…问题只是在与React-JS集成时我怀疑它是否有效,或者是因为React-Native不知何故忽略了done。fetch()返回的承诺没有done函数。React-Native支持的承诺协议的.done()位在babel/browsers中没有实现(目前)…但他说上面的代码在React-Native中运行良好…问题只是在与React-JS集成时我怀疑它是否有效,或者它之所以有效是因为React native以某种方式忽略了已完成的操作。fetch()返回的Promise没有done函数。Promise协议中的.done()位没有在babel/Browser中实现,该位用于响应本机支持。