proxytable 配置怎么看属性

问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
如何实现线上环境使用setting.host + '/api/sop/',本地dev请求localhost:3000呢?
const instance = axios.create({
baseURL: setting.host + '/api/sop/',
timeout: 20000,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
proxyTable: {
target: "http://127.0.0.1:3000",
changeOrigin: true,
pathRewrite: {
'^/api': ""
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
用的vue-resource,理论上思路是一样的。proxyTable和nginx的反向代理是一样的道理,拦截特定的url,转发到其他服务器。
proxyTable: {
target: 'http://10.0.0.10:8080',
changeOrigin: true,
pathRewrite: {
'^/api': '/api'
this.$http.post('/api/login',{
username: 'xxx',
password: 'xxx'
}).then((response) =& {
}, (response) =& {
# 生产环境 nginx
location /api {
proxy_pass http://10.0.0.10:8080/
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
可以配置一个环境变量,通过判断环境变量确定使用哪一种配置
process.NODE_ENV === 'LOCAL' ? proxyTableLocal : proxyTableServer
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
设置后, npn run dev阶段, 本地如果访问'/get/apple, 本地服务器会帮你访问拿到远程的数据, 变相的实现了跨域功能
打开config/index.js, 添加proxyTable属性
module.exports = {
build: {...}
proxyTable: {
target: ':6688',
changeOrigin: true
同步到新浪微博
分享到微博?
Hi,欢迎来到 SegmentFault 技术社区!⊙▽⊙ 在这里,你可以提出编程相关的疑惑,关注感兴趣的问题,对认可的回答投赞同票;大家会帮你解决编程的问题,和你探讨技术更新,为你的回答投上赞同票。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:vue-cli跨域问题,设置proxyTable无效??? - 特酷吧
vue-cli跨域问题,设置proxyTable无效???
来自"SegmentFault"&&& 19:20&&&
vue-cli跨域问题,设置proxyTable无效???
下面是config/index.js配置
// see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path')
module.exports = {
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
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
//设置地址映射表 当浏览器访问/api就会跳转到下方target地址
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)
找了各种解决办法,都不行。有大神知道是什么原因么?小女子刚刚入前端坑,还有很多不了解,希望有大神能给指导下。!vue-cli 配置的proxyTable代理请求api只能在开发环境下用吗?运行build打包后放到apache上不起作用
这是配置proxyTable: {
target: 'http://news-',
changeOrigin: true,
pathRewrite: {
'^/api': '/api'
你好 请问你的问题解决了吗?烦请私信一下好吗?十分感谢
你还没有登录,请先登录或注册慕课网帐号
9065人关注
1420人关注
Copyright (C)
All Rights Reserved | 京ICP备 号-2

我要回帖

更多关于 proxytable 配置 的文章

 

随机推荐