<div style="float: left; width: 70%; height: 570px">
<div
id="editor2"
style="
border: 1px solid #ccc;
float: left;
width: 100%;
border-bottom: none;
margin-top: 10px;
"
></div>
<div
id="editor3"
class="text"
style="float: left; height: 500px; width: 100%"
></div>
</div>
<script type="text/javascript" src="<%= BASE_URL %>wangEditor-3.1.1/release/wangEditor.min.js"></script>
editor: "", // 取值html this.editor.txt.html(); 赋值html this.editor.txt.html(值);
mounted() {
//富文本编辑框初始化
const E = window.wangEditor;
let editor2 = document.getElementById("editor2");
let editor3 = document.getElementById("editor3");
var editor = new E(editor2, editor3);
editor.customConfig.pasteFilterStyle = false;
editor.customConfig.pasteTextHandle = function (content) {
//清除word文档粘贴过来的样式
// content 即粘贴过来的内容(html 或 纯文本),可进行自定义处理然后返回
if (content == "" && !content) return "";
var str = content;
str = str.replace(/<xml>[\s\S]*?<\/xml>/gi, "");
str = str.replace(/<style>[\s\S]*?<\/style>/gi, "");
str = str.replace(/<\/?[^>]*>/g, "");
str = str.replace(/[ | ]*\n/g, "\n");
str = str.replace(/ /gi, "");
return str;
};
//新版本将editor.customConfig.pasteFilterStyle = false;换成editor.config.pasteFilterStyle
editor.customConfig.uploadImgShowBase64 = false; // 不使用 base64 保存图片
editor.customConfig.uploadImgServer = "xxxxxxxxxx"; //上传图片地址
editor.customConfig.uploadImgMaxSize = 2 * 1024 * 1024;
editor.customConfig.uploadFileName = "img"; //上传图片名称
editor.config.uploadImgHeaders = {//设置图片请求头
Accept: 'text/x-json',
}
editor.customConfig.uploadImgHooks = {
customInsert: function (insertImg, result, editor) {
// 图片上传并返回结果,自定义插入图片的事件(而不是编辑器自动插入图片!!!)
// insertImg 是插入图片的函数,editor 是编辑器对象,result 是服务器端返回的结果
// 举例:假如上传图片成功后,服务器端返回的是 {url:'....'} 这种格式,即可这样插入图片:
var url =result.data;
insertImg(url);
// result 必须是一个 JSON 格式字符串!!!否则报错
}
}
editor.customConfig.menus = [
//自定义菜单
"head", //标题
"bold", //粗体
"italic", //斜体
"underline", //下划线
"strikeThrough", //删除线
"foreColor", //文字颜色
"backColor", //背景颜色
"link", // 插入链接
"list", // 列表
"justify", //对齐方式
"quote", //引用
"emoticon", //表情
"image", //插入图片
"table", //表格
// 'video', //插入视频
"code", //插入代码
"undo", //撤销
"redo", //重复
];
editor.create();
this.editor = editor;
},
<style scoped="scoped">
/* 解决编辑框层级太高==》覆盖其他元素的问题 */
.w-e-menu {
z-index: 1 !important;
}
.w-e-text-container {
z-index: 1 !important;
}
/* */
</style>
wangEditor富文本
最新推荐文章于 2024-04-22 16:49:11 发布