Vue配置axios

1)安装插件(一定要在项目目录下):
>: cnpm install axios
2)在main.js中配置:
import axios from 'axios'
Vue.prototype.$axios = axios; 3)在任何一个组件的逻辑中发送ajax请求:
this.$axios({
url: 'http://127.0.0.1:8000/cars/',
method: 'get',
}).then(response => {
console.log(response);
// this.cars = response.data;
}).catch(error => { // 网络状态码为4xx、5xx
console.log(error);
});
特别注意!!!
在main.js中配置
import axios from 'axios'
Vue.prototype.$axios = axios;
 

posted @ 2021-01-25 10:57  吃不棒的胖胖糖  阅读(154)  评论(0编辑  收藏  举报