当前位置: 代码迷 >> 综合 >> vue 全局使用axios
  详细解决方案

vue 全局使用axios

热度:27   发布时间:2023-10-10 19:38:10.0

在main.js中

import axios from 'axios'
Vue.prototype.$axios= axios; // axios 改写为 Vue 的原型属性

在页面中直接使用 

this.$axios.get('url地址', {
}).then(response => {console.log(response)}).catch((error) => {alert('请求失败了哦')})