You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 10:42:34