react中axios使用

在文件目录下执行安装命令:

npm add axios

在文件中引入

import axios from 'axios'
 
使用范例:
 
  componentDidMount(){
    axios.get('http://localhost:3001/todolist')
    .then((res)=>(
      this.setState({list : [...res.data]})
    ))
    .catch(()=>{alert('error')})
    console.log('componentDidMount')
  }
posted @ 2020-06-30 22:51  雪糕战士  阅读(1464)  评论(0编辑  收藏  举报