From 8ed125f553d3c69fb030e9d0db666d187ca22549 Mon Sep 17 00:00:00 2001 From: WXL <1785969728@qq.com> Date: 星期三, 11 六月 2025 14:49:31 +0800 Subject: [PATCH] 统计完成 --- src/components/WangEditor/index.vue | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-) diff --git a/src/components/WangEditor/index.vue b/src/components/WangEditor/index.vue new file mode 100644 index 0000000..f4b9aa5 --- /dev/null +++ b/src/components/WangEditor/index.vue @@ -0,0 +1,57 @@ +<template> + <div> + <div ref="editor" style="text-align: left;"></div> + </div> +</template> + +<script> +import E from 'wangeditor'; + +export default { + name: 'WangEditor', + data() { + return { + editor: null, // WangEditor 瀹炰緥 + }; + }, + props: { + content: { + type: String, + default: '' + } + }, + watch: { + // 褰撶埗缁勪欢浼犲叆鐨� content 鍙樺寲鏃讹紝鏇存柊缂栬緫鍣ㄥ唴瀹� + content(newContent) { + if (this.editor && newContent !== this.editor.txt.html()) { + this.editor.txt.html(newContent); + } + } + }, + mounted() { + // 鍒濆鍖� WangEditor + this.editor = new E(this.$refs.editor); + this.editor.config.onchange = () => { + // 缂栬緫鍣ㄥ唴瀹瑰彉鍖栨椂锛岃Е鍙� input 浜嬩欢浼犻�掔粰鐖剁粍浠� + this.$emit('input', this.editor.txt.html()); + }; + // 閰嶇疆鑿滃崟鍜屽叾浠栬缃� + this.editor.config.menus = [ + 'head', 'bold', 'italic', 'underline', 'image', 'link', 'list', 'undo', 'redo' + ]; + this.editor.config.zIndex = 1000; + // 鍒涘缓缂栬緫鍣� + this.editor.create(); + // 璁剧疆鍒濆鍐呭 + if (this.content) { + this.editor.txt.html(this.content); + } + }, + beforeDestroy() { + // 閿�姣佺紪杈戝櫒瀹炰緥锛岄噴鏀捐祫婧� + if (this.editor) { + this.editor.destroy(); + } + } +}; +</script> -- Gitblit v1.9.3