javascript - vue2.0 project uses webpack to package and go online
过去多啦不再A梦
过去多啦不再A梦 2017-06-08 11:02:41
0
1
692

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?

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
阿神

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!