Vanessa219 / vditor

♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。An In-browser Markdown editor, support WYSIWYG (Rich Text), Instant Rendering (Typora-like) and Split View modes.
https://b3log.org/vditor
MIT License
8.09k stars 844 forks source link

TypeError: Cannot read properties of undefined (reading 'currentMode') #1595

Closed XCLHove closed 3 months ago

XCLHove commented 3 months ago

编辑模式

描述问题

代码:

<script setup lang="ts">
import {onMounted} from "vue";
import Vditor from 'vditor'
import 'vditor/dist/index.css'

let vditor: Vditor = null

onMounted(() => {
  vditor = new Vditor('vditor', {})
  console.log(vditor.getValue())
})
</script>

<template>
  <div class="container">
    <div id="vditor"></div>
  </div>
</template>

<style scoped>
.container {
  box-sizing: border-box;
  padding: 30px 0;
}
</style>

报错:

TypeError: Cannot read properties of undefined (reading 'currentMode')
    at a (index.min.js:1:64846)
    at t3.getValue (index.min.js:1:262946)
    at App.vue?t=1711609992352:12:26

期待的结果

截屏或录像

image.png

版本信息

其他信息

Vanessa219 commented 3 months ago

demo 上是正常的,这个错误信息看不出具体的问题。

0000005 commented 2 months ago

请问怎么解决的?

0000005 commented 2 months ago

如果new了Vditor之后,马上操作vditor对象,就会报错。把操作逻辑移动到 点击事件里,延迟操作vditor的时机。 就运行正常了。 目测Viditor没有初始化完成。

0000005 commented 2 months ago

这里有初始化完成的回调事件吗? @Vanessa219 这种情况下如何处理比较好? image

0000005 commented 2 months ago

我看到了,用after回调函数