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

How to define variables in vue.js

王林
王林Original
2020-11-25 16:59:026370browse

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>

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)
## 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!

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