使用axios在reactjs中获取TypeScript错误
我在react项目中使用Axios for API,但出现错误 C:/xampp/htdocs/invest19beta/src/Components/PersonList.tsx中的TypeScript错误 C:/xampp/htdocs/invest19beta/src/Components/PersonList.tsx(20,56): 类型“never”上不存在属性“name”。TS2339使用axios在reactjs中获取TypeScript错误,reactjs,react-native,axios,Reactjs,React Native,Axios,我在react项目中使用Axios for API,但出现错误 C:/xampp/htdocs/invest19beta/src/Components/PersonList.tsx中的TypeScript错误 C:/xampp/htdocs/invest19beta/src/Components/PersonList.tsx(20,56): 类型“never”上不存在属性“name”。TS2339 从“React”导入React; 从“axios”导入axios; 导出默认类PersonList
从“React”导入React;
从“axios”导入axios;
导出默认类PersonList扩展React.Component{
状态={
人员:[]
}
componentDidMount(){
axios.get()https://jsonplaceholder.typicode.com/users')
。然后(res=>{
const persons=资源数据;
这个.集合状态({persons});
})
}
render(){
返回(
{this.state.persons.map(person=>- {person.name}
)}
)
}
}
我正在使用Axios API@keikai有一些人
没有属性名称
,使用可选链接
或条件运算符
设置默认值我正在使用Axios API@keikai有一些人
没有属性名称
,使用可选链接
或条件运算符
设置默认值
import React from 'react';
import axios from 'axios';
export default class PersonList extends React.Component {
state = {
persons: []
}
componentDidMount() {
axios.get('https://jsonplaceholder.typicode.com/users')
.then(res => {
const persons = res.data;
this.setState({ persons });
})
}
render() {
return (
<ul>
{ this.state.persons.map(person => <li>{person.name}</li>)}
</ul>
)
}
}