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>

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章