1,使用npm安装: npm install wangeditor (注意 wangeditor 全部是小写字母)
2,定义一个放富文本的元素
<div id="editorElem"></div>
3,愉快的配置富文本
let editor = new E('#editorElem')
editor.customConfig.showLinkImg = false;
editor.customConfig.uploadImgServer = '服务器地址'; // 上传图片到服务器
editor.customConfig.withCredentials = true;
editor.customConfig.uploadImgParamsWithUrl = true;
editor.customConfig.uploadFileName = 'file';
editor.customConfig.uploadImgHooks = {
// 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
// (但是,服务器端返回的必须是一个 JSON 格式字符串!!!否则会报错)
customInsert: function (insertImg, result, editor) {
console.log(result);
if(result.status == 200){
let imgUrl = result.data;
insertImg(imgUrl.domain+imgUrl.url)//将内容插入到富文本中
}
}
};
//用户操作(鼠标点击、键盘打字等)导致的内容变化之后,会自动触发此函数并获取富文本中的所有内容
editor.customConfig.onchange = (html) => {
this.form.editorContent = html
}
editor.customConfig.zIndex = 1; //防止富文本编辑器被别的内容所覆盖
editor.create();
此后就能愉快的和wangEditor3玩耍了,更多内容请参考wangEditor3使用手册。