vue+ts项目全局组件提示unknown,element-plus/global,Vue - Official无效

624 阅读1分钟

全局属性引入方式的改变

declare module "vue" {
  interface ComponentCustomProperties {
    ElButton: (typeof import("element-plus"))["ElButton"];
  }
}

批量导入旧版的element-plus/global

  • 我们可以在全局类型文件(vite-env.d.ts)中这样写
  • ‘///‘ 是有意义的不要删掉了
  • 如果在全局tsconfig.json中引入了 ’element-plus/global‘ 那可以不需要 ’reference‘ 了
/// <reference types="element-plus/global" />
import * as ElementPlusGlobal from "@vue/runtime-core";
declare module "vue" {
  interface ComponentCustomProperties extends ElementPlusGlobal.GlobalComponents {}
}