一,npm安装
npm install --save axios vue-axios
二,main.js设置
import axios from 'axios'
Vue.prototype.$http = axios
三,组件内使用
this.$http.post('http://127.0.0.1/main.php?cid=1')
.then(res=>{
//验证是否成功获取数据
console.log(res);
}).catch(error=>{
//数据错误时的异常处理
console.log(error);
})
Tom哥的博客博文分类和索引页面地址:https://blog.csdn.net/tom_wong666/article/details/84137820