vue 全局使用axios

在main.js中

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

在页面中直接使用 

this.$axios.get('url地址', {
})
    .then(response => {
        console.log(response)
    })
    .catch((error) => {
        alert('请求失败了哦')
    })
发布了111 篇原创文章 · 获赞 19 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_34607371/article/details/103199207