调整尺寸_wangEditor2使用手册

开源 vue2/3 富文本编辑器wangEditor5

今天给大家分享一个超优秀的支持js/vue/react图文编辑器组件wangEditor5。

wangEditor5 一款开源的不依赖任何第三方框架,配置简单,可用于 jQuery Vue React 等。

行代码即可创建一个功能健全的富文本编辑器。

文档提供了vue2/vue3中配置使用。

https://www.wangeditor.com/v5/for-frame.html#vue3

安装

yarn add @wangeditor/editor
# 或者 npm install @wangeditor/editor --save

yarn add @wangeditor/editor-for-vue@next
# 或者 npm install @wangeditor/editor-for-vue@next --save

快速使用

<template>
    <div style=&#;border: 1px solid #ccc&#;>
      <Toolbar
        style=&#;border-bottom: 1px solid #ccc&#;
        :editor=&#;editorRef&#;
        :defaultConfig=&#;toolbarConfig&#;
        :mode=&#;mode&#;
      />
      <Editor
        style=&#;height: 500px; overflow-y: hidden;&#;
        v-model=&#;valueHtml&#;
        :defaultConfig=&#;editorConfig&#;
        :mode=&#;mode&#;
        @onCreated=&#;handleCreated&#;
      />
    </div>
</template>

<script>
import &#;@wangeditor/editor/dist/css/style.css&#; // 引入 css

import { onBeforeUnmount, ref, shallowRef, onMounted } from &#;vue&#;
import { Editor, Toolbar } from &#;@wangeditor/editor-for-vue&#;

export default {
  components: { Editor, Toolbar },
  setup() {
    // 编辑器实例,必须用 shallowRef
    const editorRef = shallowRef()

    // 内容 HTML
    const valueHtml = ref(&#;<p>hello</p>&#;)

    // 模拟 ajax 异步获取内容
    onMounted(() => {
        setTimeout(() => {
            valueHtml.value = &#;<p>模拟 Ajax 异步设置内容</p>&#;
        }, )
    })

    const toolbarConfig = {}
    const editorConfig = { placeholder: &#;请输入内容...&#; }

    // 组件销毁时,也及时销毁编辑器
    onBeforeUnmount(() => {
        const editor = editorRef.value
        if (editor == null) return
        editor.destroy()
    })

    const handleCreated = (editor) => {
      editorRef.value = editor // 记录 editor 实例,重要!
    }

    return {
      editorRef,
      valueHtml,
      mode: &#;default&#;, // 或 &#;simple&#;
      toolbarConfig,
      editorConfig,
      handleCreated
    };
  }
}
</script>

兼容性

  • 兼容主流的 PC 浏览器,如 Chrome Firefox Safari Edge 等
  • 暂不支持移动端编辑(支持移动端查看)
  • 不再支持 IE 浏览器

wangEditor 非常不错开发后台web富文本编辑器插件,感兴趣的可以去看看。

// 文档地址
https://www.wangeditor.com/
// 仓库地址
https://github.com/wangeditor-team/wangEditor-for-vue3

OK,今天就分享到这里了。

原文链接:,转发请注明来源!