1、找到vue 项目下的配置文件 /config/index.js

2、找到 proxyTable 配置项

proxyTable: {
        '/api': {
            target: 'http://www.xxx.com', // 需要跨域请求的地址或者IP
            changeOrigin: true, //  表示是否跨域
            pathRewrite: {
                '^/api': '' // 表示需要rewrite重写的
            }
        }
    }

3、使用axios 发送请求

axios.get('/api/report/data.json').then((res) => { 
  console.log(res)
}).catch((err) => {
  console.log(err)
})

3、请求地址说明

实际请求地址是 http://www.xxx.com/report/data.json  需要把target配置项改 /api 在这里即  http://www.xxx.com

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-09
  • 2022-01-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-11
  • 2021-06-05
  • 2022-12-23
  • 2021-10-14
相关资源
相似解决方案