Vue学习记录(八)--------安装使用axios

1、安装axios依赖

npm install axios

2、带参数的get请求的方式,通过 params 设置参数:

axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

3、get请求-直接在 URL 上添加参数 ID=12345


axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

4、post请求-带参数的方式

axios.post('/user', {
    firstName: 'Fred',        // 参数 firstName
    lastName: 'Flintstone'    // 参数 lastName
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
发布了73 篇原创文章 · 获赞 7 · 访问量 9694

猜你喜欢

转载自blog.csdn.net/GaoXiR/article/details/105095495
今日推荐