vue.js - vue-cli跨域问题,设置proxyTable无效???

查看:3015
本文介绍了vue.js - vue-cli跨域问题,设置proxyTable无效???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

vue-cli跨域问题,设置proxyTable无效???


下面是config/index.js配置

// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')

module.exports = {
  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
  },
  dev: {
    env: require('./dev.env'),
    port: 8080,
    autoOpenBrowser: true,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {  //设置地址映射表 当浏览器访问/api就会跳转到下方target地址      
        '/api': {
            target: 'http://127.0.0.1:3000/api/',
            changeOrigin: true,
            pathRewrite: {                
                '^/api/': ''
            }
        }
    },
    cssSourceMap: false
  }
}

运行测试访问前台报错504错误

后台报错

[HPM] Error occurred while trying to proxy request user/addUser from 127.0.0.1:8
080 to http://127.0.0.1:3000/api/ (ECONNREFUSED) (https://nodejs.org/api/errors.
html#errors_common_system_errors)

找了各种解决办法,都不行。有大神知道是什么原因么?
小女子刚刚入前端坑,还有很多不了解,希望有大神能给指导下。!

解决方案

5xx 是服务端出错。504(网关超时):服务器作为网关或代理,但是没有及时从上游服务器收到请求。

这篇关于vue.js - vue-cli跨域问题,设置proxyTable无效???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆