一、在vue框架中首先需要先安装依赖
npm install axios --save
二、在项目中的main.js中引用
import axios from 'axios';
Vue.prototype.$axios = axios;
三、在页面中进行使用
get 方式
axios({
headers:{},
url:“ ”, //url
params:{},
}).then(function(res){ //成功回调
}).catch(function(err){ //失败回调
})
post方式
axios({
method:’post’, //请求方式
headers:{},
url:“ ”, //url
data:this.$qs.stringify({}) //参数
}).then(function(res){ //成功回调
}).catch(function(err){ //失败回调
})