When you use components in vue to make requests, you inevitably need to set the baseURL. But it is best not to write this baseURL in a global vue component. If it is written into a component, you will find that it is encrypted if you modify it after packaging.
Okay, here is a way to introduce global variables.
1. Create a new js file:
##File content As follows:
const BASE_URL = 'http://192.168.0.108:7878/zkview/' export default { BASE_URL }
import global_ from './../static/config/global'
Vue.prototype.GLOBAL = global_; axios.defaults.baseURL = global_.BASE_URL;
alert(this.GLOBAL.BASE_URL);
The above is the detailed content of How to use global variables in vue. For more information, please follow other related articles on the PHP Chinese website!