10.使用axios实现真实的api请求

  1. export const getArticle = () =>{
  2. return dispatch =>{
  3. setTimeout(()=>{
  4. // dispatch(eat('煎饼'))
  5. dispatch(()=>{
  6. axios.get('/v1/article/list').then(res=>{
  7. console.log('article',res)
  8. })
  9. })
  10. },2000)
  11. }
  12. }

解决跨域问题

  1. 1.
  2. npm run eject
  3. 2.
  4. package.json 文件末尾添加 "proxy": "http://api.shudong.wang"
  5. 3.
  6. axios.get('/v1/article/list').then(res=>{
  7. console.log('article',res)
  8. })