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.25k stars 852 forks source link

id 不存在时给出对应提示 #1562

Closed ponysb closed 5 months ago

ponysb commented 6 months ago

描述问题

已经加载成功了但是还是报这个错

image

期待的结果

正常使用

版本信息

qe-present commented 6 months ago

使用的vue吗?

qe-present commented 6 months ago

onMounted

Vanessa219 commented 6 months ago

我这里无法重现,相关代码在 https://github.com/Vanessa219/vditor/blob/0346f19d83cef6f69929d5d43ba64219cff6e0cb/src/index.ts#L83 ,还麻烦看看是什么问题导致的,这边好对应进行修改。

pengge commented 5 months ago

使用vue3在刚写完的时候发现也出现这个问题,经过排查发现实际是这个地方:是初始化id的时候不正确导致的

异常的如下:


<template>
  <section id="hero">
     <!-- 指定一个容器 -->
     <div id="vditor"></div>
  </section>
</template>
<script>
import { ref, onMounted } from 'vue';
import Vditor from 'vditor';
import 'vditor/dist/index.css';

export default {
  setup() {
    const vditor = ref(null);

    onMounted(() => {
      vditor.value = new Vditor(vditor.value //此处, { 
        height: '50vh',
        width: '50vw',
        cache:{
            id:"vditor"
        }
      });
    });

    return { vditor };
  }
};
</script>

正确的如下:


<template>
  <section id="hero">
     <!-- 指定一个容器 -->
     <div id="vditor"></div>
  </section>
</template>
<script>
import { ref, onMounted } from 'vue';
import Vditor from 'vditor';
import 'vditor/dist/index.css';

export default {
  setup() {
    const vditor = ref(null);

    onMounted(() => {
      vditor.value = new Vditor("vditor", {
        height: '50vh',
        width: '50vw',
        cache:{
            id:"vditor"
        }
      });
    });

    return { vditor };
  }
};
</script>

是不是可以考虑如果id传进来不正确给个tips呢?