Vue reads static configuration files to solve the problem of dist modifying external reference configuration files

At present, because the front-end deployment of the company is deployed without a network, we package the Vue project into a dist package, and configure the external request address or the request address of other relevant parties on site. In order to solve this problem, so record the solution

  1. Create a static folder under public and create config.js
    insert image description here

  2. config.js sets the variables we need, remember to set the windows variables, do not set the scope
    insert image description here

  3. We know that vue is a single-page application, and config.js is introduced under the public index.html.

<script src="<%= BASE_URL %>static/config.js"></script>

insert image description here

insert image description here
4. Directly use the static position under 5.dist where needed
insert image description here

Guess you like

Origin blog.csdn.net/qq_42900469/article/details/127906450