toast-ui/editor 报错 undefined value或者innerhtml=null解决

蒋俊
2023-12-01

先给出npm官网地址
https://www.npmjs.com/package/@toast-ui/editor
无论你用cdn还是vue都会爆这种错,这是因为markdown插件其浏览器解析顺序导致的,废话不多说,给出解决办法
在你的初始化方法外面套一层window.onload即可

<template>
  <body>
    <div id="editor">123213</div>
  </body>
</template>

<script>
import 'codemirror/lib/codemirror.css' // Editor's Dependency Style
import '@toast-ui/editor/dist/toastui-editor.css'
import Editor from "@toast-ui/editor"; // Editor's Style

window.onload = ()=>{
  const editor = new Editor({
    el: document.querySelector('#editor'),
    height: '500px',
    initialEditType: 'markdown',
    previewStyle: 'vertical'
  });

  editor.getMarkdown();
}
export default {
  name: "Edit"
}
</script>



 类似资料: