1.查看项目是否包含axios,如果没有就安装依赖,打开图形界面工具,在“运行依赖”中搜索 axios 并安装
安装完毕后继续
2.打开main.js完成三步:
(1)导包
(2)配置全局请求根路径
(3)挂载到vue
// axios
import axios from 'axios'
// 配置请求根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/finder/api'
// 挂载到vue
Vue.prototype.$http = axios
3.发送请求:
// 请求可以为 get、put、post、delete,返回一个promise对象
this.$http.post('login', this.form)
// 可以采用await的方式接收返回参数
async login () {
const res = await this.$http.post('login', this.form)
console.log(res)
}
Vue集成Axios教程
本文详细介绍了如何在Vue项目中集成Axios库进行HTTP请求,包括检查与安装依赖、配置全局请求根路径以及如何发送get、post等类型的请求。
289

被折叠的 条评论
为什么被折叠?



