Vue3+ ts中如何进行全局挂载

main.ts中通过 config.globalProperties 进行全局挂载

app.config.globalProperties.$cache = cache

vue后缀文件中在setup中使用

import { getCurrentInstance} from 'vue'
const { proxy } = getCurrentInstance()
proxy.$cache

最后定义$cache类型

在src/shims-vue.d.ts文件中添加

declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$message: ElMessage
$cache: ICacheType
}
}
posted @ 2022-03-16 16:07  翻不了身的咸鱼  阅读(1064)  评论(0)    收藏  举报