When developing the vue project, due to cross-domain problems in webpack, I modified the proxyTable configuration of dev under the index.js subfile of the config file in the root directory to solve the problem, but when it came to packaging and online Sometimes there will be problems with these paths:
For example:
1. Configure in the index.js file:
proxyTable:{
'/api': {
target: 'http://api.*******.cn',
changeOrigin: true,
pathRewrite: {
'^api':'api'
}
}
}
2. Use vue-resoure
in a file in vue that needs get/post.this.$http.get('api/**/**/**/hello',...).then((res) => {
...
}).catch((err) => {
...
})
The result is:
1. Using the dev command during the development process can solve cross-domain problems, but the link will not work after packaging.
Question:
If you don’t have to manually go to the url of this.$http.get every time, is there any way to solve it?
阿神2017-06-08 11:04:41
Extract all the URLs into a separate file (apis.js) and then control apis.js in one file.
Then use process.env.NODE_ENV === 'production'
in apis.js to distinguish between the development environment and the production environment. Just export the URLs of the development version and the production version respectively.