vue中简单介绍如何使用axios
安装 axios
npm install axios
axios.post('/api/test',param)
.then(function(res) {
console.log(res);
})
.catch(function(err) {
console.log(err);
});
首先在主入口文件main.js中引用,之后挂在vue的原型链上
import axios from 'axios’
Vue.prototype.$axios= axios
在组件中使用
this.$axios.get('api/getNewsList').then((resp)=>{
console.log(resp);
}).catch((err)=>{
console.log(err);
})