当前位置: 首页 > news >正文

vue封装wangEditor

components下面创建WangEditor.vue

<template><div><toolbarstyle="border-bottom: 1px solid #ccc":editor="editor":defaultConfig="toolbarConfig":mode="mode"/><editorstyle="height: 500px; overflow-y: hidden"v-model="modifiedContent":defaultConfig="defaultEditorConfig":mode="mode"@onCreated="onCreated"@onChange="sendMessage"/></div>
</template><script>
import globalConfig from "@/config";
const { zixun_host } = globalConfig;
import Vue from "vue";
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
const defaultEditorConfig = {// JS 语法MENU_CONF: {},// 其他属性...
};
// 修改 uploadImage 菜单配置
defaultEditorConfig.MENU_CONF["uploadImage"] = {server: "上传图片地址",fieldName: "file",maxFileSize: 5 * 1024 * 1024, // 5Mtimeout: 30 * 1000, // 30秒//【注意】不需要修改的不用写,wangEditor 会去 merge 当前其他配置
};
export default Vue.extend({name: "WangEditor",props: {content: String,toolbarConfig: Object,},data() {return {modifiedContent: "",headers: {Authorization:"token"},editor: null,defaultEditorConfig: defaultEditorConfig,mode: "default", // or 'simple'};},components: {Editor,Toolbar,},/*** 通过监听props的变化,在watch选项中进行处理。* @author  我*/watch: {content(newVal) {this.modifiedContent = newVal;},modifiedContent(newVal) {// 在这里可以进行进一步处理//   console.log("Modified Content:", newVal);},},beforeDestroy() {const editor = this.editor;if (editor == null) return;editor.destroy(); // 组件销毁时,及时销毁编辑器},created() {},mounted() {},methods: {//编辑器创建完毕时的回调函数。onCreated(editor) {this.editor = Object.seal(editor); // 一定要用 Object.seal() ,否则会报错console.log(this.editor);},sendMessage() {this.$emit("message-sent", this.modifiedContent);},},
});
</script>
<style src="@wangeditor/editor/dist/css/style.css"></style>

main.js中注册这个全局组件
通过这种方式,可以在每个页面上使用组件,而无需在每个页面中重复导入和注册"@wangeditor/editor-for-vue"组件。记得确保已经安装好"@wangeditor/editor-for-vue"依赖。
组件之间可以通过props和事件来进行参数传递
使用 ↓

		<div style="border: 1px solid #ccc; width: 500px"><WangEditor:content="form.content":toolbarConfig="toolbarConfig"@message-sent="handleMessage"/></div>
const toolbarConfig = {};
toolbarConfig.excludeKeys = ["todo", //待办"emotion", //表情"insertLink", //超链接"insertVideo", //表情"insertImage", //网络图片"group-video", //视频"codeBlock", //代码块"divider", //分割线"fullScreen", //全屏
];
data() {return {form: formInit(),toolbarConfig: toolbarConfig,};},
	/*** 接收组件传来的值* @author  我*/handleMessage(message) {console.log("Received message:", message);this.form.content = message;},
http://www.lryc.cn/news/158565.html

相关文章:

  • 【Spring Boot 源码学习】深入 FilteringSpringBootCondition
  • docker 笔记6:高级篇 DockerFile解析
  • 微信小程序navigateTo进入页面后返回原来的页面需要携带数据回来
  • Python照片压缩教程详解
  • 软路由的负载均衡设置:优化网络性能和带宽利用率
  • CH06_第一组重构(上)
  • RHCSA-VMware Workstation Pro-Linux基础配置命令
  • YOLO-NAS详细教程-姿势估计实现
  • 【扩散模型 李宏毅B站教学以及基础代码运用】
  • SpringBoot隐藏文件
  • 常见数据库介绍对比之SQL关系型数据库
  • OLED透明屏模块:引领未来显示技术的突破
  • Python_操作记录
  • 常用激活函数整理
  • uniapp 地图跳转到第三方导航软件 直接打包成apk
  • CentOS 8 通过YUM方式升级最新内核
  • java 版本企业招标投标管理系统源码+功能描述+tbms+及时准确+全程电子化
  • Python爬虫数据存哪里|数据存储到文件的几种方式
  • 软件测试/测试开发丨Web自动化 测试用例流程设计
  • git撤销修改命令
  • EOCR-AR电机保护器自动复位的启用条件说明
  • Apache nginx解析漏洞复现
  • .NET之后,再无大创新
  • 【大麦小米学量化】什么是量化交易?哪些人适合做量化交易?
  • 计算机视觉的应用12-卷积神经网络中图像特征提取的可视化研究,让大家理解特征提取的全过程
  • el-table中点击跳转到详情页的两种方法
  • RT-DETR个人整理向理解
  • 易点易动库存管理系统与ERP系统打通,帮助企业实现低值易耗品管理
  • 【笔试强训选择题】Day34.习题(错题)解析
  • “现代”“修饰”卷积神经网络,何谓现代