工作120:富文本组件封装

<template lang="html"><div class="editor"><!--定义的为表头的属性--><div ref="toolbar" class="toolbar"></div><!--定义的为表格的属性--><div ref="editor" class="text"></div></div>
</template>
<script>
/*引入王edit插件*/
import E from 'wangeditor'
import {getAction, postAction} from "@/api";
import {ACCESS_TOKEN} from "@/store/KeyConstants";
/*开始引入Vue的模块*/
import Vue from "vue";
export default {name: 'EditorBar',data() {return {editor: null,info_: null,UploadVidio:'',}},model: {prop: 'value',event: 'change'},props: {value: {type: String,default: ''},isClear: {type: Boolean,default: false}},watch: {isClear(val) {// 触发清除文本域内容if (val) {this.editor.txt.clear()this.info_ = null}},value: function(value) {if (value !== this.editor.txt.html()) {this.editor.txt.html(this.value)}},//value为编辑框输入的内容,这里我监听了一下值,当父组件调用得时候,如果给value赋值了,子组件将会显示父组件赋给的值},created() {/*控制上传图片的逻辑*/getAction("/content/upload_url/"+1).then(res=>{this.UploadVidio=res.data}).then(res=>{this.seteditor()this.editor.txt.html(this.value)})},methods: {seteditor() {const token = Vue.ls.get(ACCESS_TOKEN);/*选中对应的元素*/this.editor = new E(this.$refs.toolbar, this.$refs.editor)/*设置存储照片的格式*/// this.editor.config.uploadImgShowBase64 = true // base 64 存储图片this.editor.config.uploadImgServer = 'http://xcff.feizhisoft.com/api/v1/upload/picture'// 配置服务器端地址this.editor.config.uploadImgHeaders = {'Authorization': `Bearer ` + token}// 自定义 headerthis.editor.config.uploadFileName = 'file' // 后端接受上传文件的参数名this.editor.config.uploadImgMaxSize = 2 * 1024 * 1024 // 将图片大小限制为 2Mthis.editor.config.uploadImgMaxLength = 6 // 限制一次最多上传 3 张图片this.editor.config.uploadImgTimeout = 3 * 60 * 1000 // 设置超时时间// 配置菜单this.editor.config.menus = ['head', // 标题'bold', // 粗体'fontSize', // 字号'fontName', // 字体'italic', // 斜体'underline', // 下划线'strikeThrough', // 删除线'foreColor', // 文字颜色'backColor', // 背景颜色'link', // 插入链接'list', // 列表'justify', // 对齐方式'quote', // 引用'emoticon', // 表情'image', // 插入图片'table', // 表格'video', // 插入视频'code', // 插入代码'undo', // 撤销'redo', // 重复'fullscreen' // 全屏]this.editor.config.uploadImgHooks = {fail: (xhr, editor, result) => {// 插入图片失败回调},success: (xhr, editor, result) => {// 图片上传成功回调},timeout: (xhr, editor) => {// 网络超时的回调},error: (xhr, editor) => {// 图片上传错误的回调},customInsert: (insertImg, result, editor) => {// 图片上传成功,插入图片的回调//result为上传图片成功的时候返回的数据,这里我打印了一下发现后台返回的是data:[{url:"路径的形式"},...]//insertImg()为插入图片的函数//循环插入图片// for (let i = 0; i < 1; i++) {// postAction('/content/picture',{file})let url = 'http://xcff.feizhisoft.com/'+ result.datainsertImg(url)// }}}this.editor.config.onchange = (html) => {this.info_ = html // 绑定当前逐渐地值this.$emit('change', this.info_) // 将内容同步到父组件中}// 创建富文本编辑器this.editor.create()}}
}
</script><style lang="css">
.editor {width: 100%;margin: 0 auto;position: relative;z-index: 0;
}
.toolbar {border: 1px solid #ccc;
}
.text {border: 1px solid #ccc;min-height: 500px;
}
</style>

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415607.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql 常用命令与备份恢复 整理

常用命令 编辑1:使用SHOW语句找出在服务器上当前存在什么数据库&#xff1a;mysql> SHOW DATABASES;2:2、创建一个数据库MYSQLDATAmysql> CREATE DATABASE MYSQLDATA;3:选择你所创建的数据库mysql> USE MYSQLDATA; (按回车键出现Database changed 时说明操作成功&…

/lib/libcrypto.so“ not found,is 32-bit instead of 64-bit

关于百度导航与百度云推送冲突 只需要加入红色部分 defaultConfig {applicationId "com.tianxin.mient.leapp"minSdkVersion 15targetSdkVersion 27versionCode 19versionName "19.0"// multiDexEnabled truejavaCompileOptions {annotationProces…

运用Zabbix实现内网服务器状态及局域网状况监控(2) —— 环境配置

一、基本要求 Zabbix支持如下操作系统&#xff1a; LinuxIBM AIXFreeBSDNetBSDOpenBSDHP-UXMac OS XSolarisWindows: 2000, Server 2003, XP, Vista, Server 2008, 7, 8, Server 2012 (只能跑 Zabbix agent) 软件需要&#xff1a; 数据库 MySQL&#xff1a; 5.0.3 或者以上&am…

lodash 常用的方法总结(持续更新)

lodash的引入 var _ require(lodash);castArray _.castArray将一个值铸造为数组如果它不是数组类型。 _.castArray(1); // > [1]_.castArray({ a: 1 }); // > [{ a: 1 }]_.castArray(abc); // > [abc]_.castArray(null); // > [null]_.castArray(undefined); //…

WEB技术分类

HTMLXHTML ▪ HTML 5 ▪ CSS ▪ TCP/IPXMLXML ▪ XSL ▪ XSLT ▪ XSL-FO ▪ XPath ▪ XPointer ▪ XLink ▪ DTD ▪ XML Schema ▪ DOM ▪ XForms ▪ SOAP ▪WSDL ▪ RDF ▪ RSS ▪ WAP ▪ Web ServicesWeb脚本JavaScript ▪ HTML DOM ▪ DHTML ▪ VBScript ▪ AJAX ▪ jQuery …

Linux入门——适合初学者

Linux入门——适合初学者学习Linux也有一阵子了&#xff0c;这过程中磕磕撞撞的&#xff0c;遇到了问题&#xff0c;也解决了一些问题&#xff0c;学习的路子是曲折的&#xff0c;想总结点啥的&#xff0c;让刚刚学习Linux的不会望而生畏。 为啥我们要学习Linux 技术的价值不…

Tomcat 配置 login 和 gas

1.首先下载tomcat 2.配置环境变量 export PATH$PATH:/Users/wangchengcheng/Downloads/UtilitySoftWare/Work/ServerTools/apache-tomcat-7.0.82/bin 3.发布login gms 的部署包 4. 修改 server.xml /Users/wangchengcheng/Downloads/UtilitySoftWare/Work/ServerTools/apache-…

1 微信公众号开发 服务器配置 有什么用

启用并设置服务器配置后&#xff0c;用户发给公众号的消息以及开发者需要的事件推送&#xff0c;将被微信转发到该URL中。 换句话说&#xff0c;开发者需要监听这个URL&#xff0c;处理数据&#xff0c;并做出反应。

Android极光推送,Manifest merger failed with multiple errors, see logs

极光推送加载jar包时&#xff0c;报错 Manifest merger failed with multiple errors, see logs解决方法 加入红色部分defaultConfig {applicationId "com.nxin.client.liteapp"minSdkVersion 15targetSdkVersion 27versionCode 19versionName "19.0"// …

svn在linux下的使用(转)

svn在linux下的使用(转)ubuntu命令行模式操作svn 首先要安装SVN客户端到你的系统才能操作各种命令 apt-get install subversion 1、将文件checkout到本地目录 svn checkout path&#xff08;path是服务器上的目录&#xff09; 例如&#xff1a;svn checkout svn://192.168.1.1…

[Bzoj4540][Hnoi2016] 序列(莫队 + ST表 + 单调队列)

4540: [Hnoi2016]序列 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1567 Solved: 718[Submit][Status][Discuss]Description 给定长度为n的序列&#xff1a;a1,a2,…,an&#xff0c;记为a[1:n]。类似地&#xff0c;a[l:r]&#xff08;1≤l≤r≤N&#xff09;是指序列&am…

2 微信公众号开发 服务器配置 Token验证

服务器配置的主要难点就是Token验证。 官方文档&#xff1a;https://mp.weixin.qq.com/wiki?tresource/res_main&idmp1445241432 接入指南&#xff1a;https://mp.weixin.qq.com/wiki?tresource/res_main&idmp1421135319 用户服务器端主要需要做的工作&#xff0c;…

Android 10分钟集成极光推送

1、首先申请key https://www.jiguang.cn/accounts/login/form 2、app build.gradle添加jar依赖 compile cn.jiguang.sdk:jpush:3.0.7 compile cn.jiguang.sdk:jcore:1.1.3 compile me.leolin:ShortcutBadger:1.1.16aar//消息桌面显示 注意最新依赖是&#xff1a; compile c…

Python requests介绍之接口介绍

Python requests介绍 引用官网介绍 Requests 唯一的一个非转基因的 Python HTTP 库&#xff0c;人类可以安全享用。 Requests 允许你发送纯天然&#xff0c;植物饲养的 HTTP/1.1 请求&#xff0c;无需手工劳动。你不需要手动为 URL 添加查询字串&#xff0c;也不需要对 POST 数…

前端学习(2623):Vuex初步识别

Vuex 是什么&#xff1f; Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态&#xff0c;并以相应的规则保证状态以一种可预测的方式发生变化。Vuex 也集成到 Vue 的官方调试工具 devtools extension (opens new window)&#x…

3 微信公众号开发 接受普通消息

用户如果在公众号发送内容&#xff0c;微信服务器会把消息转发到我们到服务器上&#xff0c;我们需要及时做出处理&#xff0c;给用户反馈。 文档地址&#xff1a;https://mp.weixin.qq.com/wiki?tresource/res_main&idmp1421140453 例如&#xff0c;在微信公众号发送消…

Android 动画以view中心点旋转动画

旋转180度 Animation anim new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); anim.setFillAfter(true); // 设置保持动画最后的状态 anim.setDuration(500); // 设置动画时间 anim.setInterpolator(new AccelerateInterpo…