Global.vue
要共用的全域参数
<script>const _token = "";const userid = "";export default { _token, //使用者地址 userid,};</script>
使用方式2:
直接在需要使用的档案 引入全域性变数模组
看範例
<template><div>{{ token }}</div></template><script>import global_ from '../config/Global'//引用模组进来export default {data () {return {token:global_.token,}}}</script>
使用方式2:
在入口档案 main.js,
将Global.vue 挂载至 Vue.prototype
import global_ from './config/Global'Vue.prototype.GLOBAL = global_//挂载到Vue例项上面
//直接通过this访问全域性变数。
<template><div>{{ token }}</div></template><script>export default {data () {return {token:this.GLOBAL.token,}}}</script>