Home > Web Front-end > Vue.js > How to define variables in vue.js

How to define variables in vue.js

王林
Release: 2020-11-30 14:35:02
Original
6466 people have browsed it

The method of defining variables in vue.js: first define a vue module; then use const to define variables, and use export to expose them; finally, import them in the module that needs to use global variables.

How to define variables in vue.js

The operating environment of this tutorial: Windows 10 system, vue version 2.9. This method is suitable for all brands of computers.

(Related video sharing: javascript video tutorial)

The steps to define variables are as follows:

1. Define a vue module and define variables with const. And use export to expose it to the outside world.

Globle.vue

<script>
// 服务端url
    const SERVER_BASE_URL = &#39;http://10.199.xxx.x0:8081/&#39;
    export default{
        SERVER_BASE_URL
    }
</script>
Copy after login

2. For modules that use global variables, use

test.vue

import global_ from &#39;components/common/Global.vue&#39;
console.log(global_.SERVER_BASE_URL)
Copy after login
## after importing. #Related recommendations:

vue.js tutorial

The above is the detailed content of How to define variables in vue.js. 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