vue定义全域性变数

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>

<<:  Day27 参加职训(机器学习与资料分析工程师培训班),专题讨论

>>:  Ruby基本介绍(二) && Palindrome-number解法

30天学会C语言: Day 1-C语言起手式

Function 在程序设计中的 Function(有时候翻译函式)类似数学中的 Function(...

Day 6:设定你的 Hexo 布景主题:Next(上)

昨天我们安装了 Next 这个布景主题,今天就要来介绍如何编辑设定 Next,以及 Next 提供了...

React Hooks - useContext

当我们要将父元素的资料传递到子元件的时候会使用 props,但假设有很多个 component,曾曾...

[Day 3] 取得台股资料(基本篇)

一、前言 想要进行资料分析,要做的第一件事当然是收集资料,所幸现在是2021,我们不需要为了股票资料...

Youtube API — 示范 Colaboratory来进行 Python 开发

「鲑鱼均,因为一场鲑鱼之乱被主管称为鲑鱼世代,广义来说以年龄和脸蛋分类的话这应该算是一种 KNN 的...