当我通过带有url axios的axios发送请求时,将api的url与类星体dev服务器的url连接起来,我怎能忽略这种连接,只发送baseUrl,类星体的axios的baseUrl有任何配置吗?
src/启动从“axios”导入axios
export default async ({ Vue }) => {
axios.defaults.baseURL = 'http//:localhost:3000/'
Vue.prototype.$axios = axios
}组件没有:
this.$axios({
url : 'backend/spots/all',
}).then(response=>{
this.allSlots = response.data
})发布于 2019-11-03 20:03:47
根据类星体文档,您可以尝试如下:
// src/boot/axios.js
const axiosInstance = axios.create({
baseURL: 'http//:localhost:3000'
})
export default async ({ Vue }) => {
Vue.prototype.$axios = axiosInstance
...
}
export { axiosInstance }若要在某些vue \ js文件中使用:
import { axiosInstance } from 'src/boot/axios'
axiosInstance.get('/some-endpoint')发布于 2019-11-03 19:43:53
我不确定,但您能否尝试将axios.defaults.baseURL = 'http//:localhost:3000/'更改为axios.defaults.baseURL = 'http://localhost:3000/' (更改冒号位置)?
发布于 2021-03-05 08:08:35
任何读过这个的人。根据类星体axios引导文档的说法,你可以尝试一种更干净的方法.
import Vue from 'vue'
import axios from 'axios'
// we add it to Vue prototype
// so we can reference it in Vue files as this.$axios
// without the need to import axios or use vue-axios
Vue.prototype.$axios = axios
// can also create an axios instance specifically for the backend API
const api = axios.create({ baseURL: 'https://api.example.com' })
Vue.prototype.$api = api
export { axios, api }https://stackoverflow.com/questions/58680554
复制相似问题