main全局挂载
小于 1 分钟
main全局挂载
main.ts
扩展全局变量的接口内容,需要扩展ComponentCustomProperties这个接口
declare module "vue" {
export interface ComponentCustomProperties {
$Bus: typeof mit,
$metaList: any;
}
}
<!-- 定义全局变量 -->
app.config.globalProperties.$metaList = ''
更新全局变量
<!-- login.vue -->
let internalInstance: any = getCurrentInstance();
internalInstance.appContext.config.globalProperties.$metaList = '33333333333333';
使用
<!-- 页面中直接使用 -->
<template>
<div class="container">
{{ $metaList }}
</div>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue';
import { ElMessage } from 'element-plus';
import type { FormInstance, FormRules } from 'element-plus';
<!-- ts中使用 -->
const { proxy }: any = getCurrentInstance()
console.log('打印元数据')
console.log(proxy.$metaList)
</script>
<style>
</style>