当前位置: 首页 > news >正文

Vue 安装 wangEditor 富文本编辑器

最近遇到Vue项目需要添加一个富文本编辑,纠结了好久,最后选择 wangEditor ,然后整理了一些wangEditor  的使用教程

1.安装

npm install @wangeditor/editor --save

#vue2 
npm install @wangeditor/editor-for-vue --save

2.使用

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

<!-- 一定要记得引入style -->
<style src="@wangeditor/editor/dist/css/style.css"></style>

<script>
  import { Editor, Toolbar } from '@wangeditor/editor-for-vue'

  export default Vue.extend({
    components: { Editor, Toolbar },
    data() {
      return {
        editor: null,
        html: '<p>hello</p>',
        toolbarConfig: {
            toolbarKeys : ['bold', 'underline', 'headerSelect', 'italic', 'through', 'code', 'sub', 'sup', 'clearStyle', 'color', 'bgColor', 'fontSize', 'fontFamily', 'indent', 'delIndent', 'justifyLeft', 'justifyRight', 'justifyCenter', 'justifyJustify', 'lineHeight',  'divider', 'insertLink', 'codeBlock', 'blockquote','redo', 'undo', 'fullScreen',  'bulletedList', 'numberedList', 'insertTable'
        ]
      },
        editorConfig: { placeholder: '请输入内容...' },
        mode: 'default', // or 'simple'
      }
    },
    methods: {
      onCreated(editor) {
        this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错

        //打印所有工具
        //console.log(this.editor.getAllMenuKeys());
      },
    },
    mounted() {
      // 模拟 ajax 请求,异步渲染编辑器
      setTimeout(() => {
        this.html = '<p>模拟 Ajax 异步设置内容 HTML</p>'
      }, 1500)
    },
    beforeDestroy() {
      const editor = this.editor
      if (editor == null) return
      editor.destroy() // 组件销毁时,及时销毁编辑器
    },
  })
</script>

复制以上代码,即可在页面上使用富文本编辑器

但是功能并非上面这一点点,内含很强大功能,有的功能只有在使用的时候,才会去研究。

文档如下:

官方教程

wangEditor官网

Github地址

相关文章:

  • 【Redis】Mac系统一键安装redis
  • Python基于Django和人脸识别的在线票务系统设计与实现
  • Java进阶——注解一文全懂
  • MR-图解
  • 学生考勤请假管理系统
  • ai说话人分离 | 基于语音大模型进行说话人拆分
  • 【精华】为什么class在前端开发中不常用?
  • 【云原生之kubernetes实战】在k8s环境中高效部署Vikunja任务管理工具(含数据库配置)
  • 【C++】Rusage(一)
  • 广义线性模型下的数据分析(R语言)
  • 当JMeter遇见AI:性能测试进入智能时代(附实战案例)
  • 虚拟仿真无线路由器5G和2.4G发射信号辐射对比(虚拟仿真得出最小安全距离,与国际标准要求一致)
  • 百度 API 教程 006:使用BMapGL.Marker3D绘制带高度的点纹理贴图
  • 市场加速下跌,但监管「坚冰」正在消融
  • 【练习】【贪心】力扣1005. K 次取反后最大化的数组和
  • 可以用于promise面试的例子--其1
  • 基于单片机的机床切屑运输系统设计
  • cv2.solvePnP 报错 求相机位姿
  • 车载电源管理新标杆NCV8460ADR2G 在汽车电子负载开关中的应用
  • 删除idea recent projects 记录
  • 如何自己创网站/网站到首页排名
  • 网站模式下做淘宝客/廊坊百度推广电话
  • 哪些网站做品牌特卖/东营网站推广公司
  • dw如何做商业网站/淘宝seo培训
  • 企业展厅图片/seo一个月工资一般多少
  • 网站关键词过多/goole官网