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.
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 = 'http://10.199.xxx.x0:8081/' export default{ SERVER_BASE_URL } </script>
2. For modules that use global variables, use
test.vue
import global_ from 'components/common/Global.vue' console.log(global_.SERVER_BASE_URL)
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!