Vue3+ts导入Vue-grid-layout报错<html>Vue: Could not find a declaration file for module ‘vue-grid-layout-v

 省流:直接从第三点看

1.问题场景

遇到需要实现拖拽+缩放功能的自定义布局时导入组件Vue-grid-layout时,项目中import报错,网上找的办法都没有解决。

2.网上找的帖子VUE3开发遇到的“TypeScript error TS7016: Could not find a declaration file for module ‘./**.vue‘”问题

3.最终解决办法

(1)

确保你使用的是支持 Vue 3 的 Vue-Grid-Layout 版本。你可以尝试安装最新的 beta 版本:

   npm install vue-grid-layout@3.0.0-beta1

(2) 

如果 TypeScript 无法识别 Vue-Grid-Layout 的类型,你可以在项目根目录创建一个 vue-grid-layout.d.ts 文件,内容如下:

   declare module 'vue-grid-layout' {

     import { DefineComponent } from 'vue'

     export const GridLayout: DefineComponent<{}, {}, any>

     export const GridItem: DefineComponent<{}, {}, any>

   }

(3)

  • 在 tsconfig.json 中添加类型声明文件:

确保你的 tsconfig.json 文件包含以下配置:

   {

     "compilerOptions": {

       // ... 其他选项

       "types": ["vue-grid-layout"]

     }

   }

做到这一步我在项目的vue文件中import已经没有报错了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值