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')
  }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM