Vue.js 1.0 我们常使用 vue-resource (官方ajax库), Vue 2.0 发布后作者宣告不再对 vue-resource 进行更新, 推荐我们使用 axios (基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用)

安装 axios

使用 npm

npm install axios
使用 yarn

yarn add axios
使用 axios

如同使用 vue-resource 一样使用
main.js

import axios from 'axios'
Vue.prototype.$http = axios
执行 GET 请求

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

相关文章:

  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
猜你喜欢
  • 2022-01-23
  • 2021-07-13
  • 2022-02-15
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案