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