记录Property ‘xxx‘ does not exist on type问题解决方法

在Vue3 + TS 的demo项目中 , 使用app.config.globalProperties.$session = sessionStorage封装了一个全局的$session , 但是出现了Property '$session' does not exist on type的报错提示 , 查找了下发现是需要写一个声明文件

在src文件夹下新建一个xxx.d.ts文件

import {ComponentCustomProperties } from '@/vue'
declare module '@vue/runtime-core'{
  interface ComponentCustomProperties {
    $session: any,
  }
}

声明后可正常使用了

猜你喜欢

转载自blog.csdn.net/liyp921210/article/details/129674199
今日推荐