首页 > 其他分享 >Vue3集成wangeditor5

Vue3集成wangeditor5

时间:2024-04-02 17:26:52浏览次数:12  
标签:集成 editorRef console log return editor Vue3 wangeditor5 const

参考连接

https://www.wangeditor.com/v5/for-frame.html#使用-1

效果图

相关依赖

<template>
	<div>
		<div style="border: 1px solid #ccc; margin-top: 10px">
			<Toolbar
				:editor="editorRef"
				:defaultConfig="toolbarConfig"
				:mode="mode"
				style="border-bottom: 1px solid #ccc"
			/>
			<Editor
				:defaultConfig="editorConfig"
				:mode="mode"
				v-model="valueHtml"
				style="height: 200px; overflow-y: hidden"
				@onCreated="handleCreated"
				@onChange="handleChange"
				@onDestroyed="handleDestroyed"
				@onFocus="handleFocus"
				@onBlur="handleBlur"
				@customAlert="customAlert"
				@customPaste="customPaste"
			/>
		</div>
	</div>
</template>

<script>
import '@wangeditor/editor/dist/css/style.css';
import { onBeforeUnmount, ref, shallowRef, onMounted } from 'vue';
import { Editor, Toolbar } from '@wangeditor/editor-for-vue';

export default {
	components: { Editor, Toolbar },
	setup() {
		// 编辑器实例,必须用 shallowRef,重要!
		const editorRef = shallowRef();

		// 内容 HTML
		const valueHtml = ref('');

		// 模拟 ajax 异步获取内容
		onMounted(() => {
			setTimeout(() => {
				valueHtml.value = '请输入';
			}, 1500);
		});

		const toolbarConfig = {};
		const editorConfig = { placeholder: '请输入内容...' };

		// 组件销毁时,也及时销毁编辑器,重要!
		onBeforeUnmount(() => {
			const editor = editorRef.value;
			if (editor == null) return;

			editor.destroy();
		});

		// 编辑器回调函数
		const handleCreated = (editor) => {
			console.log('created', editor);
			editorRef.value = editor; // 记录 editor 实例,重要!
		};
		const handleChange = (editor) => {
			console.log('change:', editor.getHtml());
		};
		const handleDestroyed = (editor) => {
			console.log('destroyed', editor);
		};
		const handleFocus = (editor) => {
			console.log('focus', editor);
		};
		const handleBlur = (editor) => {
			console.log('blur', editor);
		};
		const customAlert = (info, type) => {
			alert(`【自定义提示】${type} - ${info}`);
		};
		const customPaste = (editor, event, callback) => {
			console.log('ClipboardEvent 粘贴事件对象', event);

			// 自定义插入内容
			editor.insertText('xxx');

			// 返回值(注意,vue 事件的返回值,不能用 return)
			callback(false); // 返回 false ,阻止默认粘贴行为
			// callback(true) // 返回 true ,继续默认的粘贴行为
		};

		const insertText = () => {
			const editor = editorRef.value;
			if (editor == null) return;

			editor.insertText('hello world');
		};

		const printHtml = () => {
			const editor = editorRef.value;
			if (editor == null) return;
			console.log(editor.getHtml());
		};

		const disable = () => {
			const editor = editorRef.value;
			if (editor == null) return;
			editor.disable()
		};

		return {
			editorRef,
			mode: 'default',
			valueHtml,
			toolbarConfig,
			editorConfig,
			handleCreated,
			handleChange,
			handleDestroyed,
			handleFocus,
			handleBlur,
			customAlert,
			customPaste,
			insertText,
			printHtml,
			disable
		};
	},
};
</script>

标签:集成,editorRef,console,log,return,editor,Vue3,wangeditor5,const
From: https://www.cnblogs.com/openmind-ink/p/18111067

相关文章

  • 视频监控/云存储/AI智能分析平台EasyCVR集成时调用接口报跨域错误的原因排查
    EasyCVR视频融合平台基于云边端架构,可支持海量视频汇聚管理,能提供视频监控直播、云端录像、云存储、录像检索与回看、智能告警、平台级联、智能分析等视频服务。平台兼容性强,支持多协议、多类型设备接入,包括:国标GB/T28181协议、RTMP、RTSP/Onvif协议、海康Ehome、海康SDK、大华SDK......
  • vue3+ts项目配置别名
    说明在项目开发中,需要通过配置别名来方便开发读取文件目录。配置文件vite.config.jsimport{defineConfig}from'vite'importvuefrom'@vitejs/plugin-vue'import{resolve}from"path";constpathSrc=resolve(__dirname,"src");exportdefault......
  • Vue3连接mqtt订阅消息
    Vue3中使用以及订阅没有安装可使用npminstallmqtt--save(暂时使用了[email protected])页面引入引用mqtt库不要直接引用mqtt会报错importmqttfrom'mqtt/dist/mqtt'代码:1.获取动态配置(关于mqtt的动态配置)<script>////引入mqttimportmqttfrom"mqt......
  • Vue2 和 Vue3 中的 v-model 的区别#记录
    vue3对v-model的语法进行了改动。vue2中有两种方式实现数据的双向绑定(组件与外部数据的双向绑定),一种是使用v-model,另一种是使用v-bind.sync修饰符。vue2中的v-model,主要是进行value属性的绑定和input事件的派发。<ChildComponentv-model="pageTitle"/>//等价于<Child......
  • ELK介绍与Spring Boot集成使用
    ELK介绍与SpringBoot集成使用LogstashLogstash是一个具有实时管道功能的开源数据收集引擎。Logstash可以动态地统一来自不同来源的数据,并将数据规范化到您选择的目的地。清理和民主化您的所有数据,以实现各种高级下游分析和可视化用例。一般Logstash与Elasticsearch和Kiba......
  • vue3从精通到入门9:计算属性computed
    在Vue3中,computed 是一个用于创建计算属性的工具,它基于组件的响应式依赖进行复杂的计算,并返回一个新的响应式引用。计算属性是Vue的一个核心概念,它提供了一种声明式的方式来执行基于其依赖的响应式数据的计算。computed使用:计算属性与常规属性类似,但是它们是基于它们......
  • jacoco+jenkins集成代码覆盖率
    1.需先在jenkins服务器上安装apache-ant(已安装)检查ant是否安装:ant-version 2.然后在jenkins服务器和测试环境上都安装jacoco(jenkins服务器和summer服务器已安装)cd /neworiental/jacocowgethttps://repo1.maven.org/maven2/org/jacoco/jacoco/0.8.5/jacoco-0.8.5.zipu......
  • vue3 设置el-dialog height超过滚动条
     方法一:<stylescoped>::v-deep.el-dialog.el-dialog-body{height:500px;overflow-y:auto;}</style> 如果要设置动态的高度话,则要在setup里面设置 <script>exportdefaultdefineComponent({setup:{constcssContent=ref({heigh......
  • SpringBoot集成MyBatis-Plus快速入门Demo
    目录1.MyBatis-Plus概述2.MyBatis-Plus框架结构3. MyBatis-Plus快速入门3.1 创建表3.2 创建工程3.3 导入依赖3.4添加配置文件application.yml,配置数据库信息3.5 创建实体类(包括自动填充)3.6创建配置类(包括配置乐观锁、分页、逻辑删除等插件) 3.7编写自动填......
  • vue3中播放flv流视频,以及组件封装超全
    实现以上功能的播放,只需要传入一个流的地址即可,当然组件也只有简单的实时播放功能下面直接上组件里面的flvjs通过npmiflv.js直接下载 <template><divclass="player"style="position:relative;"><pstyle="position:absolute!important;top:10px;lef......