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