Vue.js 中使用 Axios 进行 Ajax 请求

Vue.js 推荐在 2.0 及更高版本中使用 Axios 来处理 Ajax 请求。Axios 是一个基于 Promise 的 HTTP 库,支持浏览器和 Node.js 环境。Github 开源地址:Axios GitHub

使用 response.data 读取 JSON 数据:

// GET 实例网站列表
const app = new Vue({
el: '#app',
data() {
  return {
    info: null
  }
},
mounted() {
axios
  .get('/api/sites')
  .then(response => (this.info = response.data))
  .catch(error => console.error(error));
}
});
pdf 文件大小:90.17KB