Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 671|回复: 0

[默认分类] vue : 本地调试跨域问题的解决办法:proxyTable

[复制链接]
  • TA的每日心情
    开心
    2021-12-13 21:45
  • 签到天数: 15 天

    [LV.4]偶尔看看III

    发表于 2020-8-16 13:46:12 | 显示全部楼层 |阅读模式
    本来我是不想写的,但为了加深印象还是写一写吧。
    ./config/index.js

    1. module.exports = {
    2.   dev: {
    3.     // Paths
    4.     assetsSubDirectory: "static",
    5.     assetsPublicPath: "/",
    6.     proxyTable: { "/api": {  //使用"/api"来代替"http://charon-satellite.com"
    7.             target: "http://xxx.charon-satellite.com", //源地址
    8.             secure: false,  // 如果是https接口,需要配置这个参数
    9.             changeOrigin: true, //改变源
    10.             pathRewrite: {
    11.               "^/api": "" //路径重写
    12.             }
    13.         }
    14.     },
    15.     // Various Dev Server settings
    16.     host: "localhost", // can be overwritten by process.env.HOST
    17.     port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    18.     autoOpenBrowser: false,
    19.     errorOverlay: true,
    20.     notifyOnErrors: true,
    21.     poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
    22.    
    23.     /**
    24.      * Source Maps
    25.      */
    26.     // https://webpack.js.org/configuration/devtool/#development
    27.     devtool: "cheap-module-eval-source-map",
    28.     // If you have problems debugging vue-files in devtools,
    29.     // set this to false - it *may* help
    30.     // https://vue-loader.vuejs.org/en/options.html#cachebusting
    31.     cacheBusting: true,
    32.     cssSourceMap: true
    33.   },
    34.   build: {
    35.     // Template for index.html
    36.     index: path.resolve(__dirname, "../dist/index.html"),
    37.     // Paths
    38.     assetsRoot: path.resolve(__dirname, "../dist"),
    39.     assetsSubDirectory: "static",
    40.     assetsPublicPath: "./",
    41.     /**
    42.      * Source Maps
    43.      */
    44.     productionSourceMap: true,
    45.     // https://webpack.js.org/configuration/devtool/#production
    46.     devtool: "#source-map",
    47.     // Gzip off by default as many popular static hosts such as
    48.     // Surge or Netlify already gzip all static assets for you.
    49.     // Before setting to `true`, make sure to:
    50.     // npm install --save-dev compression-webpack-plugin
    51.     productionGzip: false,
    52.     productionGzipExtensions: ["js", "css"],
    53.     // Run the build command with an extra argument to
    54.     // View the bundle analyzer report after build finishes:
    55.     // `npm run build --report`
    56.     // Set to `true` or `false` to always turn it on or off
    57.     bundleAnalyzerReport: process.env.npm_config_report
    58.   }
    59. }
    复制代码


    ./api.js (管理接口的JS文件)

    1. ...
    2. // export const base = "http://xxx.charon-satellite.com"; // 线上
    3. export const base = "/api";  // 本地
    4. export const qs = require("qs")
    5. // public
    6. export const login = base + "/xxx/xxx/dologin"; // 登录
    7. ...
    复制代码


    原理:简单的说就是利用了vue所用的node.js服务器环境,建立代理服务器,使本地的域名与线上域名相同。
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-4-26 07:17 , Processed in 0.412228 second(s), 46 queries .

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表