Home > Web Front-end > JS Tutorial > body text

How to use global variables in vue

一个新手
Release: 2017-09-19 10:11:54
Original
3437 people have browsed it

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
}
Copy after login

2. Modify the entry main.js file

import global_ from './../static/config/global'
Copy after login

and then use the variable

Vue.prototype.GLOBAL = global_;
axios.defaults.baseURL = global_.BASE_URL;
Copy after login

like this You can use variables. When using them, you can use them like this:

 alert(this.GLOBAL.BASE_URL);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!