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
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM