Vue3+TypeScript中使用vue3-summernote-editor报错求助
解决Vue3+TypeScript中vue3-summernote-editor导入错误
错误1:找不到模块'vue3-summernote-editor'或其类型声明(ts(2307))
该包暂无官方TypeScript类型定义,需手动添加类型声明:
- 在项目
src目录下创建types文件夹,新建vue3-summernote-editor.d.ts文件,写入以下内容:
declare module 'vue3-summernote-editor' { import type { DefineComponent } from 'vue'; const SummernoteEditor: DefineComponent<{}, {}, any>; export default SummernoteEditor; }
- 确保
tsconfig.json包含类型目录配置,示例:
{ "compilerOptions": { "typeRoots": ["./src/types", "./node_modules/@types"] } }
错误2:'SummernoteEditor'已声明但未被使用(ts(6133))
导入组件后需完成注册并在模板中使用,修改后的代码示例:
<script lang="ts"> import { defineComponent, ref } from "vue"; import SummernoteEditor from 'vue3-summernote-editor'; export default defineComponent({ name: "surveytemplate", components: { SummernoteEditor // 注册组件 }, setup() { const editorContent = ref(''); return { editorContent }; }, }); </script> <template> <SummernoteEditor v-model="editorContent" /> <!-- 使用组件 --> </template>
额外注意:需要引入summernote样式文件,可在main.ts或当前组件中添加:
import 'summernote/dist/summernote-lite.css';
内容的提问来源于stack exchange,提问作者JayK
相关产品推荐
相关产品推荐

