Reactjs React Can';无法提取到数组
我试图获取数据并将其放入一个数组中,因此在我的状态下创建了一个名为 洛卡伦 那我会的Reactjs React Can';无法提取到数组,reactjs,Reactjs,我试图获取数据并将其放入一个数组中,因此在我的状态下创建了一个名为 洛卡伦 那我会的 fetch('http://localhost:3001/Lokalen/') .then(response => response.json()) .then(data => this.setState({lokalen:data})) console.log(this.state.data) } 但我的数组似乎仍然是空的 我已经检查过是
fetch('http://localhost:3001/Lokalen/')
.then(response => response.json())
.then(data => this.setState({lokalen:data}))
console.log(this.state.data)
}
但我的数组似乎仍然是空的
我已经检查过是否提取了正确的东西,是的,如果我使用
然后我可以在我的日志中看到所需的数据。
我只是无法在我的数组中获取它
有人知道为什么吗?正在componentdidmount中执行提取,似乎您正在尝试获取计算机上已存在的文件。 当您使用Localhost时,您是在本地计算机上托管服务器 使用
fetch()
时,只需指定文件/API端点的路径即可
从
你可以这样做
fetch(/Lokalen/, {
method: "GET",
headers: {
"Content-Type": "application/json"
},
credentials: "same-origin"
}).then(function(response) {
response.status //=> number 100–599
response.statusText //=> String
response.headers //=> Headers
response.url //=> String
return response.text()
}, function(error) {
error.message //=> String
})
是否有可能因为需要填充而延迟数据进入阵列?有没有办法让它发挥作用