安装依赖包
npm install axios --save
npm install qs --save
封装方法
![](https://img.haomeiwen.com/i14878237/0c2d0f68e21f0af7.png)
main.js中导入方法
import {get,post}from '@/api/fetch'
Vue.prototype.get = get;
Vue.prototype.post = post;
使用封装的方法
let res = await this.get(url,{});
或者
this.get(url,{}).then(function(res){}).catch(function(err){})
网友评论