VUE使用proxy代理

mac2026-05-17  6

VUE-cli 3.0中的proxy使用方法

//vue-cli3.0 里面的 vue.config.js做配置 devServer: { proxy: { '/api': { //这里最好有一个 / target: 'http://192.168.1.22:18308', // 后台接口域名 ws: true, //如果要代理 websockets,配置这个参数 secure: false, // 如果是https接口,需要配置这个参数 changeOrigin: true, //是否跨域 pathRewrite:{ '^/api':'' } } } }

VUE-cli 2.0 中的proxy使用方法

proxyTable: { "/api": { target: "http://192.168.1.22:18308", pathRewrite: { '^/api': '/' }, // 允许跨域 changeOrigin: true }, },

proxy具体的一些其他的小细节

dev.env.js

'use strict' const merge = require('webpack-merge') const prodEnv = require('./prod.env') module.exports = merge(prodEnv, { NODE_ENV: '"development"', ADMIN_SERVER: '"/api/"', })

config - index.js

// Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: { "/api": { target: "http://192.168.1.22:18308", pathRewrite: { '^/api': '/' }, // 允许跨域 changeOrigin: true }, },

config - prod.env.js

'use strict' module.exports = { NODE_ENV: '"production"', BASE_API: '"http://202.175.236.125:18308"' //产品环境 }
最新回复(0)