vue中使用axios
2019-03-25 本文已影响0人
呆呆_c007
安装依赖包
npm install axios --save
npm install qs --save
封装方法

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