Not much nonsense to say, directly into the topic, this article to configure a different interface domain name address as an example
There is a config folder under the project root, which includes at least three files in the base project.
1.dev.env.js
2.index.js
3.prod.env.js
What we need to do is configure the first and the third one.
In fact, these two file content is to set different parameters for the production environment and publishing environment files, then open dev.en.js, development environment. The original code is as follows:
' Use strict ' const merge = require (' webpack-merge ') const PRODENV = require ('./prod.env ') module.exports = Merge (Prodenv, { node_env: ' "Development" ',})
Then we configure a BASE_API, add a line of code on the page, as follows
' Use strict ' const merge = require (' webpack-merge ') const PRODENV = require ('./prod.env ') module.exports = Merge (Prodenv, { node_env: ' Development ', Base_api: ' "https://www.baidu.com" ',})
Then, we edit the Prod.env.js file, the production environment, the original code is as follows
' Use strict ' Module.exports = { node_env: ' "Production" ',}
On the basis of this file, add a line of code, changed as follows
' Use strict ' Module.exports = { node_env: ' "Production" ', Base_api: ' "https://www.baidu.com" ',}
At last
Configure API interface address var root = Process.env.BASE_API
This time root is the common base variable, you can directly access the interface when this write: root+ "Api/home" and this variable will be automatically adjusted according to the environment, packaging will automatically change to an online address.
This variable can also be configured globally in Main.js.
Vue.prototype. $URL = Process.env.BASE_API;
The Vue CLI Scaffolding Project uses Webpack to configure different interface addresses or different variable values for the production and release environments.