怎样在 Vue 中使用 axios ?

首先安装:

npm install --save axios

也可以使用 yarn 安装。注意,yarn 的安装命令是 add,不是 install:

yarn add axios

然后在 main.js 中添加下面的代码,就可以全局使用 axios:

import axios from 'axios'
Vue.prototype.$http = axios

使用:

this.$http
  .get(baseURI)
  .then( result => {
    console.log(result.data)
  })
发布了197 篇原创文章 · 获赞 88 · 访问量 58万+

猜你喜欢

转载自blog.csdn.net/henryhu712/article/details/104092637