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)
}