vue axios 设置基础apiurl

官方文档

  • 学习新东西看官方文档不可少
  • 快速概览
  • 找到自己需要的内容

快速定位内容

  • 对一般人来说,都是遇到问题需要查文档,查完即用,不需要深究

进入主题
编辑main.js,配置:

import axios from 'axios'
axios.defaults.baseURL = 'https://www.baidu.com/'
Vue.prototype.axios = axios

使用:

this.axios.get('getImgList').then(res => console.log(res))

可能会遇到下面的报错:
isURLSameOrigin.js?cf95:57 Uncaught (in promise) TypeError: Cannot
read property ‘protocol’ of undefined
这是因为axios不是VUE插件,不能使用 Vue.use(axios) 方式引用,需要使用上述原型方式引入

猜你喜欢

转载自blog.csdn.net/example440982/article/details/80918479