tenc1239 2023-07-05 03:26 采纳率: 76%
浏览 62
已结题

vue 跨域设置 proxy 为什么无效?决绝子了

// config 配置文件

const { defineConfig } = require('@vue/cli-service')
// module.exports = defineConfig({
//   transpileDependencies: true,

// })
module.exports = {

  devServer: {

    proxy: {
      "/api/": {
        target: 'https://echarts.apache.org/examples/data/asset/data/stock-DJI.json',
        changeOrigin: true, // 跨域访问设置,true代表跨域
        ws: true,
        'secure': true, // false为http访问,true为https访问
        // 'pathRewrite': { // 路径改写规则
        //   '^/api': "/" // 以/api/为开头的改写为''
        // }
      },
    },
  },
}

// url 
let url = '/api/'   //// 这里会匹配到前面我们设置的/api/',代替为https://echarts.apache.org/examples/data/asset/data/stock-DJI.json,

      console.log('url', url)
      this.axios.get(url).then((rawData) => {}

// 运行结果
url /api/
:8081/api/:1     Failed to load resource: the server responded with a status of 404 (Not Found)

// 我希望的是 
https://echarts.apache.org/examples/data/asset/data/stock-DJI.json
这个链接 替换 let url = '/api/'

请求 是这样
 this.axios.get(https://echarts.apache.org/examples/data/asset/data/stock-DJI.json).then((rawData) => {}

实际请求时
 this.axios.get(/api/) => {}

我希望的是
https://echarts.apache.org/examples/data/asset/data/stock-DJI.json
这个链接 替换 let url = '/api/'

请求 是这样
this.axios.get(https://echarts.apache.org/examples/data/asset/data/stock-DJI.json).then((rawData) => {}

实际请求时
this.axios.get(/api/) => {}

到底要怎么搞

  • 写回答

3条回答 默认 最新

  • tenc1239 2023-07-05 17:13
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 7月13日
  • 已采纳回答 7月5日
  • 创建了问题 7月5日

悬赏问题

  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真
  • ¥15 关于#c语言#的问题,请各位专家解答!