记录wangEditor5简单使用

  1. 首先在官网找了很久的js、css下载地址,结果没找到,后面无奈只能跟着官网指导走(这一步很坑,以为能在官网找到现成的js,后面又去网上找资源,结果网上资源不行,还好后面狂找找到了)
  2.  把js、css引入前端页面,这一步很简单,就是把需要的js、css复制进项目,再引入就行
  3. 配置工具栏和编辑器,其实就是跟着官网走,按文档去配置,多尝试

 前端代码

<div class="row">
								<div class="col-sm-12">
									<div class="form-group">
										<label for="" class="col-sm-1 control-label no-padding-right">内容:<span
												class="red">*</span></label>

										<div class="col-sm-10">
											<div id="editor—wrapper">
												<div id="toolbar-container"><!-- 工具栏 --></div>
												<div id="editor-container"><!-- 编辑器 --></div>
												<label for="content"><textarea style="display:none;" id="content" name="content"></textarea></label>
											</div>
##											<textarea style="height:100px;" rows="3" class="form-control" name="content" id="content"></textarea>
										</div>

									</div>
								</div>
							</div>

 textarea块隐藏了,方便把数据传到后台去

js代码

<script type="text/javascript">

	const { createEditor, createToolbar } = window.wangEditor

//编辑器配置
	const editorConfig = {
		placeholder: 'Type here...',
		autoFocus:false,
		maxLength: 1000,
		onChange(editor) {
			const html = editor.getHtml()
			console.log('editor content', html)
			// 也可以同步到 <textarea>
			const contentVal = $("#content");
			contentVal.val(html);
			contentVal.focusin();
			contentVal.blur();

		}
	}

	const editor = createEditor({
		selector: '#editor-container',
		html: '',
		config: editorConfig,
		mode: 'default', // or 'simple'
	})

//菜单栏配置
	const toolbarConfig = {
//排除的菜单组
		excludeKeys:[
			'emotion',
			'group-image',
			'fullScreen',
			'group-video' // 排除菜单组,写菜单组 key 的值即可
		]
	}

	const toolbar = createToolbar({
		editor,
		selector: '#toolbar-container',
		config: toolbarConfig,
		mode: 'default', // or 'simple'
	})



</script>

最后页面效果如下图,上传图片、视频、附件啥的都被我排除了,毕竟产品文档也没说要做,还麻烦,得重新写上传的接口

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
WangEditor是一款基于javascript和jQuery开发的富文本编辑器,它支持常见的文本编辑操作、图片上传和格式化等功能。如果您想对WangEditor进行二次封装和使用,可以按照以下步骤进行: 1. 下载WangEditor 您可以从官网上下载WangEditor的源码文件,也可以使用npm进行安装。 2. 引入WangEditorWangEditorJS和CSS文件引入到您的HTML文件中: ```html <link rel="stylesheet" type="text/css" href="path/to/wangEditor.css"> <script type="text/javascript" src="path/to/jquery.js"></script> <script type="text/javascript" src="path/to/wangEditor.js"></script> ``` 3. 创建编辑器实例 在HTML文件中创建一个div元素,作为编辑器的容器,然后通过JavaScript代码创建编辑器实例: ```html <div id="editor"></div> <script type="text/javascript"> var editor = new wangEditor('editor'); editor.create(); </script> ``` 4. 配置编辑器 您可以通过传递配置对象来配置编辑器,例如: ```html <div id="editor"></div> <script type="text/javascript"> var editor = new wangEditor('editor'); // 配置编辑器 editor.config.uploadImgUrl = '/upload'; editor.config.uploadImgFileName = 'image'; editor.config.menus = [ 'bold', 'italic', 'underline', 'strikeThrough', 'eraser', 'foreColor', 'backColor', 'justifyLeft', 'justifyCenter', 'justifyRight', 'table', 'code', 'undo', 'redo' ]; editor.create(); </script> ``` 5. 使用编辑器 编辑器创建完成后,您可以使用它提供的方法来操作文本内容,例如: ```javascript // 获取编辑器内容 var content = editor.$txt.html(); // 设置编辑器内容 editor.$txt.html('<p>这是新的内容</p>'); ``` 以上就是二次封装和使用WangEditor的基本步骤,您可以根据自己的需要进行配置和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值