首页 > 其他分享 >vue3使用wangeditor富文本编辑器

vue3使用wangeditor富文本编辑器

时间:2022-08-26 21:56:20浏览次数:58  
标签:文本编辑 wangeditor customConfig html 楷体 editor vue3 config

 

npm下载

 1 npm i wangeditor -S         

 

在要使用的页面导入

1 import EWangEditor from "wangeditor";
2 import {onMounted, reactive} from "vue";

定义

 

 

 复制下面的代码,放到上面截图的位置即可

 1   setup() {
 2     let data = reactive({});
 3     onMounted(() => {
 4       let editor = new EWangEditor("#editor");
 5       editor.config.uploadImgShowBase64 = true;
 6       editor.config.onchangeTimeout = 400;
 7 
 8       editor.config.customAlert = (err) => {
 9         console.log(err);
10       };
11 
12       editor.customConfig = editor.customConfig
13           ? editor.customConfig
14           : editor.config;
15 
16       editor.customConfig.onchange = (html) => {
17         data.editorContent = html;
18         console.log(html);
19       };
20         //以下为新增
21       const menuItem = [  //工具栏里有哪些工具
22         "head",
23         "bold",
24         "fontSize",
25         "fontName",
26         "italic",
27         "underline",
28         "indent",
29         "lineHeight",
30         "foreColor",
31         "backColor",
32         "link",
33         "list",
34         "justify",
35         "image",
36         "video",
37       ];
38 
39       editor.config.menus = [...menuItem]; /* 应用设置好的工具栏 */
40 
41       editor.config.colors = ["#000000", "#eeece0", "#1c487f", "#4d80bf"];  /* 文字颜色、背景色可以选择哪些颜色? */
42 
43       editor.config.fontNames = [ /* 字体工具提供哪些字体? */
44         "黑体",
45         "仿宋",
46         "楷体",
47         "标楷体",
48         "华文仿宋",
49         "华文楷体",
50         "宋体",
51         "微软雅黑",
52       ];
53 
54       editor.config.height = 500;  //你可能发现这个编辑器是没法用样式调高度的?
55       //新增至此
56       editor.create();
57     });
58 
59   }

使用

1 <div name="editor" id="editor" ref="editor"></div>

运行

 

标签:文本编辑,wangeditor,customConfig,html,楷体,editor,vue3,config
From: https://www.cnblogs.com/lwl80/p/16629374.html

相关文章

  • 教程 - 深度探讨在 Vue3 中引入 CesiumJS 的最佳方式
    目录1.你应该先知道的基础知识1.1.CesiumJS的库构成1.2.选择Vite3和pnpm的理由1.3.使用External模式引入静态库-不打包静态库1.4.切勿什么都import-以及......
  • wangEditor如何能实现直接粘贴把图片上传到服务器中
    ​如何做到ueditor批量上传word图片?1、前端引用代码<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-......
  • VSCode添加自定义的Vue3.2标准模板
    创建新的用户片段 点击文件——首选项——用户片段或者用快捷Ctrl+Shift+P唤出控制台然后输入“snippets”并选择接着输入vuevscode自动生成vue.json文件{......
  • 使用vue3对数据进行分页展示
    要获取用户的滚动位置,可以在末尾添加一列空白节点。每当出现空白时意味着滑倒网页最底部,则进行渲染数据。可以使用getBoundingClientRect来判断是否在页面底部。getBoundi......
  • vue3 onMounted is called when there is no active component
    Vue版本:3.0.0出现的问题:在setup()中onMounted()onActivated(),出现警告:[Vuewarn]:onMountediscalledwhenthereisnoactivecomponentinstancetobeassoc......
  • vue3 基础-生命周期函数
    在vue中,生命周期函数可理解为"在某个时刻,会自动执行的函数".先直观感受一下图示.一共就八个:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-......
  • vue3 学习笔记
    watchletsum=ref('0');letperson=reactive({sex:‘女’,age:18,}) watch(sum,(oldVal,newVal)=>{console.log(oldVal,newVal);})/**监视reactive所定义的一......
  • vue3 vuex4 store的响应式取值
    场景:在页面中点击按钮,数量增加,值是存在store中的,点击事件,值没变。<scriptsetuplang="ts">import{useStore}from'@/vuex';conststore=useStore()constonSu......
  • Vue3中defineEmits、defineProps 是怎么做到不用引入就能直接用的
      最近正在将一个使用单文件组件的OptionsAPI的Vue2JavaScript项目升级为Vue3typescript,并利用CompositionAPI的优势。比如,下面这种 选项API 方式:......
  • vue3 基础-应用app和组件基本概念
    这篇主要对vue最基础的应用程序Application和组件Components进行一个简要和直观的认知,具体要分析的代码如下:<!DOCTYPEhtml><htmllang="en"><head><metac......