【发布时间】:2018-06-15 18:52:48
【问题描述】:
我正在通过 axios 获取数据以进行本机反应,但一直显示这样的错误消息。我该如何解决?提前致谢!
import axios from 'axios';
export default class App extends Component {
state = {
persons: []
}
async componentDidMount() {
this.fetchData();
}
fetchData = async() =>{
axios.get(`https://jsonplaceholder.typicode.com/users`)
.then(res => {
const persons = res.data;
this.setState({ persons });
})
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
{ this.state.persons.map(person => {person.name})}
</Text>
</View>
);
}
}
我在安装axios时出现错误信息:
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "axios" under a package
npm ERR! also called "axios". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR! <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/user/.npm/_logs/2018-06-15T19_16_16_279Z-debug.log
【问题讨论】:
-
如何导入axios?
-
请编辑您的问题并在此处添加相关信息。
-
完成。提前致谢。我完全糊涂了。
-
没问题。你安装了 axios 吗?
-
显示错误信息
标签: react-native axios