Table of Contents
vue uses global variables
Home Web Front-end JS Tutorial How to use global variables in vue

How to use global variables in vue

Sep 19, 2017 am 10:11 AM
use overall situation variable

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use mdf and mds files How to use mdf and mds files Feb 19, 2024 pm 05:36 PM

How to use mdf and mds files

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

What software is crystaldiskmark? -How to use crystaldiskmark?

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

How to download foobar2000? -How to use foobar2000

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

How to use NetEase Mailbox Master

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

How to use Baidu Netdisk app

How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone Feb 22, 2024 pm 05:19 PM

How to use Xiaoai Speaker How to connect Xiaoai Speaker to mobile phone

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange?

Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection' Mar 10, 2024 pm 04:34 PM

Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection'

See all articles