Quasar Axios请求错误的URL(双URL) [英] Quasar Axios request wrong URL (Double URL)

查看:392
本文介绍了Quasar Axios请求错误的URL(双URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误图片

当我通过带有URL的axios发送请求时axios连接api的url 与类星体开发服务器的URL,我怎么能忽略这一点 串联并仅在有任何配置的情况下发送API URL axios与类星体的baseUrl?

when i send request via axios with url axios concatenate url of api with the url of the quasar dev server how can i neglect this concatenation and send the API url only there is any configuration for baseUrl of axios with quasar ?

src/启动 从"axios"导入axios

src/boot import axios from '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
     })

推荐答案

根据Quasar 文档,您可以尝试以下操作:

According Quasar documentation you can try it as below:

// src/boot/axios.js

const axiosInstance = axios.create({
  baseURL: 'http//:localhost:3000'
})

export default async ({ Vue }) => {
  Vue.prototype.$axios = axiosInstance
  ...
}

export { axiosInstance }

用于某些用途| js文件:

to use in some vue | js file:

import { axiosInstance } from 'src/boot/axios'

axiosInstance.get('/some-endpoint')

这篇关于Quasar Axios请求错误的URL(双URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆