如果使用webpack
模板和vue-cli
模板,则可以在本参考文件中找到所需信息:
http://vuejs-templates.github.io/webpack/proxy.html
或者,您可以将相关配置从webpack
模板复制到本地webpack-simple
模板,而不是现在更改模板.
EDIT: more info from my local setup
这是我在config/index.js
岁以下的module.exports
岁以下 children 中所拥有的:
dev: {
env: require('./dev.env'),
port: 4200,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true
},
'/images': {
target: 'http://localhost:8080',
changeOrigin: true
},
// and so on...
上面的配置在端口4200上运行我的vue-cli
,我在端口8080上运行我的服务器.
EDIT: Corrected info about CORS after comment #4 and #5
Note:
dev.proxyTable
中的changeOrigin
选项(在webpack配置中)确保您不需要在服务器API响应上提供CORS头.changeOrigin
,那么需要确保服务器API在其响应头中包含Access-Control-Allow-Origin: *
(或等效值).References: