Home  >  Article  >  Web Front-end  >  How to use global variables in vue

How to use global variables in vue

一个新手
一个新手Original
2017-09-19 10:11:543469browse

vue uses global variables

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn