<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. 浅谈组件二封-vue

    目录 组件二封不是换一种写法 组件二封应当具备哪些条件 我认为的二封应当有哪些作用 二封的好处 先来一个列表页demo来看看效果(Vue2) 本文仅仅针对vue系列做探讨, 项目倾向于大量增删改查的后 ...

  2. jdbc封装工具类(连接池)

    c3p0配置文件: c3p0-config.xml <c3p0-config> <!-- 使用默认的配置读取连接池对象 --> <default-config> & ...

  3. superset2.0.0 支持MaxCompute 时间颗粒

    编译的时候需要在superset/superset/db_engine_specs以下路径增加一个 odps.py的文件 # Licensed to the Apache Software Found ...

  4. elasticsearch组件

    elasticsearch组件 Elasticsearch 是一个实时的分布式搜索分析引擎,它能让你以前所未有的速度和规模,去探索你的数据. 它被用作全文检索.结构化搜索.分析以及这三个功能的组合 E ...

  5. 百题计划-1 codeforces1181C Flag 暴力模拟

    https://codeforces.com/contest/1181/problem/C 题意:给一个n*m的格子(n,m<=1000),每个格子有个颜色,求可以条纹子矩阵的数量. 条纹矩阵就 ...

  6. ES bool查询

    一.bool查询包含四种操作 1.must 2.must not 3.filter 4.should 二.功能 1.must 对应mysql的 and a= 2.must not 对应mysql的 a ...

  7. 《Vue.js 3.x高效前端开发(视频教学版)》简介

    #好书推荐##好书奇遇季#<Vue.js 3.x高效前端开发(视频教学版)>,京东当当天猫都有发售.本书配套示例源码.PPT课件.思维导图.数据集.开发环境与答疑服务. 本书通过对Vue. ...

  8. 微信小程序笔记_02

    在微信小程序中使用Echarts组件 github源码地址:https://github.com/ecomfe/echarts-for-weixin gitcode源码地址:https://gitco ...

  9. mybatis-关联查询4-多对多查询

    三张表的关联查询  

  10. 对LVDS的浅显理解

    文章参考百度文库:LVDS标准及介绍 LVDS与VB1的对比:LVDS与VB1详细介绍 1.LVDS简介 LVDS( Low Voltage Differential Signaling)是一种低摆幅 ...