The structure shown above can solve the management of request URLs in large and medium-sized Vue applications. The author can introduce the domain.js in main.js and expose it as a global variable, which can be used in each component. Obtain the corresponding url address set through domain.testUrl. The benefits are as follows:
Centralized url management to facilitate later management and modification
Convenient coding, just pass domain.testUrl in the request
main.js
domain.js
The structure shown above can solve the management of request URLs in large and medium-sized Vue applications. The author can introduce the domain.js in main.js and expose it as a global variable, which can be used in each component. Obtain the corresponding url address set through domain.testUrl.
The benefits are as follows:
Centralized url management to facilitate later management and modification
Convenient coding, just pass domain.testUrl in the request
This seems to have nothing to do with vue. If you are using ES6, you can use the const module.
Call:
For this kind of problem, you can learn from the solution defined for modules in
redux
.vue also has the same model: vuex
API.js
Write a Vue plug-in. The plug-in is global.
Global variable window or vuex