The json file that changes the configuration after vue is packaged is invalid
I encountered a pitfall when writing a project today:
In the vue project, a static project.config.json file is placed under the public to configure the proxy ip address and system title and other related configurations, so that relevant changes can be made during deployment , but modifying the configuration file does not take effect after the bulid is packaged. The specific problems are as follows:
1. Create a new project.config.json file in the public folder:
{
baseUrl:'',
jumpURL:'',
}
2. Reference under utils/request.js:
import JSON from '../../public/project.config.js'
// 请求接口地址
let baseURL = JSON.baseUrl
3. Afterwards, bulid packaging:
after changing the configuration in project.config.json, it will not take effect. The specific reason has not been found
yet. The solution for others is
to replace the json file with a js file.
window.api = {
baseUrl:'',
jumpURL:'',
}
Then import this js file into public/index.html
You can use window.api directly in the project.
console.log(window.api)
// 打印出来的就是{
//baseUrl:'',
// jumpURL:'',
//}
Here's what I've found so far...