Home > Article > Web Front-end > How to use global variables in vue
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 }2. Modify the entry main.js file
import global_ from './../static/config/global'and then use the variable
Vue.prototype.GLOBAL = global_; axios.defaults.baseURL = global_.BASE_URL;like this You can use variables. When using them, you can use them like this:
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!