zoukankan      html  css  js  c++  java
  • vue3中axios请求配置代理devServer.proxy解决跨域问题

    1、根目录新建文件 vue.config.js

    module.exports = {
        devServer: {
            proxy: {
                "/api": {
                    target: "https://test3.api.domain.com", //这里设置的地址会代替axios中设置的baseURL
                    ws: true,
                    changeOrigin: true,
                    secure: true,
                    pathRewrite: {
                        '^/api': '/'
                    }
                }
            }
        }
    };

    2、
    文件 xxxxService.js,修改代码:
     
    baseURL: '/api',
     
    apiService.get('/abc/v1/fr/users?id=10')  //使用除域名部分的完整路径
    apiService.get('/efg/v1/cn/users?id=10')
     
    3、
    说明:
    //pathRewrite: {'^/api': '/'} 重写之后url为 http://192.168.1.16:8085/xxxx
    //pathRewrite: {'^/api': '/api'} 重写之后url为 http://192.168.1.16:8085/api/xxxx

    参考:https://www.cnblogs.com/Samuel-Leung/p/14276846.html

  • 相关阅读:
    VS2013快速安装教程
    软件工程课程的感想
    GitHub和Microsoft TFS对比有什么优势
    拼接素数
    C语言程序题
    vue中的实例方法的底层原理
    ios 安卓
    防抖
    伪数组转真数组的放法
    http和https的一种能力?
  • 原文地址:https://www.cnblogs.com/x00479/p/15083140.html
Copyright © 2011-2022 走看看