<template>
<div>
<div style="border: 1px solid #ccc; width: 500px">
<!-- 工具栏 -->
<Toolbar style="border-bottom: 1px solid #ccc" :editor="editor" :defaultConfig="toolbarConfig" />
<!-- 编辑器 -->
<Editor style="height: 400px; overflow-y: hidden" :defaultConfig="editorConfig" v-model="html" @onChange="onChange" @onCreated="onCreated" />
</div>
</div>
</template> <script>
import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
import Cookie from 'js-cookie'; export default {
name: 'MyEditor',
components: { Editor, Toolbar },
props: {
destDir: {
type: String,
},
},
data() {
return {
editor: null,
html: '',
toolbarConfig: {
// toolbarKeys: [ /* 显示哪些菜单,如何排序、分组 */ ],
// excludeKeys: [ /* 隐藏哪些菜单 */ ],
},
editorConfig: {
placeholder: '请输入内容...',
// autoFocus: false, // 所有的菜单配置,都要在 MENU_CONF 属性下
MENU_CONF: {},
},
};
},
methods: {
onCreated(editor) {
this.editor = Object.seal(editor); // 【注意】一定要用 Object.seal() 否则会报错
console.log('Created');
},
onChange(editor) {
// console.log('onChange', editor.getHtml()); // onChange 时获取编辑器最新内容
}, loadHtml(html) {
this.html = html;
},
insertTextHandler(html) {
const editor = this.editor;
if (editor == null) return;
console.log(html);
editor.insertText(html);
},
printEditorHtml() {
const editor = this.editor;
if (editor == null) return;
console.log(editor.getHtml());
},
disableHandler() {
const editor = this.editor;
if (editor == null) return;
editor.disable();
},
// 自定义校验图片
customCheckImageFn(src, alt, url) {
if (!src) {
return;
}
if (src.indexOf('http') !== 0) {
return '图片网址必须以 http/https 开头';
}
return true; // 返回值有三种选择:
// 1. 返回 true ,说明检查通过,编辑器将正常插入图片
// 2. 返回一个字符串,说明检查未通过,编辑器会阻止插入。会 alert 出错误信息(即返回的字符串)
// 3. 返回 undefined(即没有任何返回),说明检查未通过,编辑器会阻止插入。但不会提示任何信息
}, // 转换图片链接
customParseImageSrc(src) {
// JS 语法
if (src.indexOf('http') !== 0) {
return `${this.pictureUrl}${src}`;
}
return src;
},
},
created() {
let that = this;
this.editorConfig.MENU_CONF['uploadImage'] = {
server: process.env.VUE_APP_API_MANAGE + '/uploadFileController/editUpload.do',
fieldName: 'file',
// 继续写其他配置...
meta: {
destDir: that.destDir,
},
headers: {
adminToken: Cookie.get('adminToken'),
},
onSuccess(file, res) {
// JS 语法
console.log(`${file.name} 上传成功`, res);
},
// customInsert(res: any, insertFn: InsertFnType) {
// TS 语法
customInsert(res, insertFn) {
// JS 语法
// res 即服务端的返回结果
// 从 res 中找到 url alt href ,然后插入图片
insertFn(process.env.VUE_APP_SERVER + 'imageServer' + res.data.url, res.data.alt, res.data.href);
},

}; // 插入图片
this.editorConfig.MENU_CONF['insertImage'] = {
onInsertedImage(imageNode) {
// JS 语法
if (imageNode == null) return; const { src, alt, url, href } = imageNode;
console.log('inserted image', src, alt, url, href);
},
checkImage: that.customCheckImageFn, // 也支持 async 函数
parseImageSrc: that.customParseImageSrc, // 也支持 async 函数
};
},
mounted() {
// // 模拟 ajax 请求,异步渲染编辑器
// setTimeout(() => {
// this.html = '<p>Ajax 异步设置内容 HTML</p>';
// }, 1500);
},
beforeDestroy() {
const editor = this.editor;
if (editor == null) return;
editor.destroy(); // 组件销毁时,及时销毁 editor ,重要!!!
},
};
</script>
<style>
.w-e-full-screen-container {
bottom: 0 !important;
display: flex !important;
flex-direction: column !important;
height: 100% !important;
left: 0 !important;
margin: 0 !important;
padding: 0 !important;
position: fixed;
right: 0 !important;
top: 0 !important;
width: 100% !important;
z-index: 99999;
}
</style>
<style src="@wangeditor/editor/dist/css/style.css"></style>

vue富文本(5版本)组件的更多相关文章

  1. vue+富文本编辑器UEditor

    vue+富文本编辑器UEditor 昨天的需求是把textarea换成富文本编辑器的形式, 网上找了几种富文本编辑器ueditor.tinymce等, 觉得ueditor实现双向绑定还挺有意思, 分享 ...

  2. vue富文本vue-quill-editor

    这个富文本需要装一下插件 "quill": "^1.3.6" "quill-image-drop-module": "^1.0.3 ...

  3. vue富文本编辑器vue-quill-editor使用总结(包含图片上传,拖拽,放大和缩小)

    vue-quill-editor是vue很好的富文本编辑器,富文本的功能基本上都支持,样式是黑白色,简洁大方. 第一步下载 vue-quill-editor: npm i vue-quill-edit ...

  4. vue 富文本编辑器 项目实战用法

    1.挑个富文本编辑器 首先针对自己项目的类型,确定自己要用啥编辑器. 1.1 wangeditor 如果一般类似博客这种项目不需要花里胡哨的,功能也不要求贼多的,推荐一下wangeditor(点击跳转 ...

  5. Vue富文本编辑器(图片拖拽缩放)

    富文本编辑器(图片拖拽缩放) 需求: 根据业务要求,需要能够上传图片,且上传的图片能在移动端中占满屏幕宽度,故需要能等比缩放上传的图片,还需要能拖拽.缩放.改变图片大小.尝试多个第三方富文本编辑器,很 ...

  6. vue富文本编辑器vue-quill-editor

    1.下载Vue-Quill-Editor npm install vue-quill-editor --save 2.下载quill(Vue-Quill-Editor需要依赖) npm install ...

  7. vue富文本编辑器

    基于webpack和vue 一.npm 安装 vue-quill-editor 二.在main.js中引入 import VueQuillEditor from 'vue-quill-editor'/ ...

  8. 富文本编辑器quill---vue组件(vue-quill-editor)的使用

    1.配置webpack plugin 解决以下报错 Uncaught TypeError: Cannot read property 'imports' of undefined (image-res ...

  9. 前端富文本 js 版本

    https://s3.pstatp.com/pgc/v2/resource/tt_ueditor_v3_temple/tt-editor.all.js?20180425

  10. 适用于 Mpvue 的微信小程序富文本解析自定义组件

    废话不多说,直接上方法: 首先 npm 安装 mpvue-wxparse npm i mpvue-wxparse 接下来:使用 <template> <div> <wxP ...

随机推荐

  1. matplotlib处理数据可是化的时候出现中文显示异常,为[][]的解决方法

    1.在使用matplotlib处理数据实现可是化操作的时候,处于语言习惯,经常会使用中文做图表备注,而中文显示会出现异常,如下图: 中文显示异常 那如何解决呢,实际上我们只需要在代码中添加两行内容即可 ...

  2. twenty four

    vue基础代码 <script src="vue路径"></script> <script> const vm = new Vue({ //el ...

  3. C#中DataTable新增列、删除列、更改列名、交换列位置

    一.新增列 1.1.新增列 /*新增列*/ dataTable.Columns.Add("列名称", Type.GetType("数据类型")); /*比如添加 ...

  4. php8.0.0新功能:Match表达式

    Match表达式是基于值的一致性进行分支计算.它的比较是严格比较.Match表达式从php8.0.0起可用.示例代码: 1 $key = 'key_1'; 2 $value = match($key) ...

  5. redis-RedisTemplate.opsForValue 常用方法

    16.multiSetIfAbsent(Map<? extends K,? extends V> map) 如果对应的map集合名称不存在,则添加,如果存在则不做修改. Map value ...

  6. 【笔记】DDD实战课-人保架构欧创新

    目录 开篇 学好DDD,你能做什么? 基础 领域驱动设计:微服务设计为什么要选择 DDD? DDD的两层设计 DDD与微服务的关系 领域.子域.核心域.通用域和支撑域:傻傻分不清? 领域和子域 核心域 ...

  7. sprinboot多个子模块下 依赖包没有找到 解决方案

    最近因为在使用springboot开发项目,在开发过程中,发现自己的子模块导入通用的模块 在启动中 说找不到这个类 百度下 说我要在pom文件下 pulus 插件 那里 加上这段代码 <conf ...

  8. min-max 容斥简记

    min-max 容斥实际上就是这么个式子: \[\max(S_k) = \sum\limits_{T\subseteq S} (-1)^{|T|-k}\dbinom{|T|-1}{k-1}\min(T ...

  9. PaddleOCR(PaddleHub Serving)离线部署包制作

    PaddleOCR(PaddleHub Serving)离线部署包制作 环境与版本: 系统 CPU架构 Anaconda3 PaddlePaddle PaccleOCR 银河麒麟Server V10 ...

  10. 完全使用vscode开发python

    完全使用vscode开发python 作为Python开发,以前一直使用Pycharm社区版,因为卡顿,尝试使用vscode替换,尝试后并在工作中使用了半个月觉得真香,所以分享给大家. 更详细的视频介 ...