vue npm run build 生成的dist部署上去之后居然 发送接口不走代理?原因很简单

 

正常走代理的请求:(其实http://www.only-screen.xyz:8080/api  ==   http://www.only-screen.xyz:8888)

一般vue 项目这么打包

npm run build

config/index.js  设置:  之前一个项目我也设置这样的,部署上去没问题。

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
module.exports = {
  dev: {
    env: require('./dev.env'),
    host: 'localhost',
    port: 8080,
    autoOpenBrowser: true,
    autoOpenPage: '/login',
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/api': {
        target: 'http://localhost:8888',
        pathRewrite: {
          '^/api': '/'
        }
      }
    },
    // CSS Sourcemaps off by default because relative paths are "buggy"
    // with this option, according to the CSS-Loader README
    // (https://github.com/webpack/css-loader#sourcemaps)
    // In our experience, they generally work as expected,
    // just be aware of this issue when enabling this option.
    cssSourceMap: false
  },
  build: {
    env: require('./prod.env'),
    index: path.resolve(__dirname, '../dist/index.html'),
    assetsRoot: path.resolve(__dirname, '../dist'),
    assetsSubDirectory: 'static',
    assetsPublicPath: './',
    productionSourceMap: true,
    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],
    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }
}

效果:   http://www.only-screen.xyz:8080/api  走代理后 等同于访问: http://www.only-screen.xyz:8888  

生成的dist文件上传到 linux 、 nginx 正常代理的情况下照理说是没问题的,

但是我发现前端发送接口,居然 还是按照  8080 发出去,没有带 /api 这个 后缀,

找了好久,最后 发现是:

这个文件

箭头这一行要加上,表示是 base_url  就可以了。  不走代理就这样解决了。

over

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值