uni-app的editor的富文本编辑器
在官方文档中教程真是也太简单了,
大家可以在官方代码中找到完整的内容
https://github.com/dcloudio/hello-uniapp/blob/master/pages/component/editor/editor.vue
记住editor中的内容需要全部在项目中都有才会显示出来样式,
可以也修改一下简单的样式
在然后值得说一下的上传图片和获取输入的内容,着两个在文档没有体现
在这里重点说明一下,因为没有好好看官方文档,只看了组件中的使用,没注意看api中关于富文本上写的,所以在小程序测试的时候报错,真真是气炸了,
https://uniapp.dcloud.io/api/media/editor-context
这个官方文档中写的
还有就是这个不能封装为组件用,封装为组件会报错
uni.createSelectorQuery().select('#editor').context((res) => {console.log(res,'----------是空')this.editorCtx = res.context}).exec()
在每个使用到富文本编辑器组件的页面,配置 pages.json 文件如下:
{"pages": [ {"path": "pages/index/index","style": {"navigationBarTitleText": "uni-app","usingSwanComponents": {"editor": "dynamicLib://editorLib/editor"}}}]
}
<view class="editor-wrapper"><editor id="editor" class="ql-container" placeholder="开始输入..." showImgSize showImgToolbar showImgResize@statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady" @input="getText"></editor></view>//获取内容getText(e){//获取数据var that = this;getApp().globalData.editor = e.detail.html// console.log(e.detail.html);//带标签内容// console.log(e.detail.text);//纯文本内容},//文件上传
insertImage() {var that = this;uni.chooseImage({count: 1,success: (res) => {console.log('insert image success')const tempFilePaths = res.tempFilePaths;uni.uploadFile({url: url.uploadimageEider,filePath: tempFilePaths[0],name: 'image',success: (uploadFileRes) => {let data=JSON.parse(uploadFileRes.data)console.log(data,"编辑详情的时候返回照片地址")var url=data.ip + data.data[0]if(data.errno=="0"){that.editorCtx.insertImage({src: url,alt: '图像',success: function() {}})}else{that.showToast(back.msg)}},fail:() =>{uni.hideLoading();that.showToast("图片上传失败,请联系开发!")}});}})}
在官方文档中修改地方editor.vue完整文档
<template><view class="container"><view class="page-body"><view class='wrapper'><view class='toolbar' @tap="format" style="height: 120px;overflow-y: auto;"><view :class="formats.bold ? 'ql-active' : ''" class="iconfont icon-zitijiacu" data-name="bold"></view><view :class="formats.italic ? 'ql-active' : ''" class="iconfont icon-zitixieti" data-name="italic"></view><view :class="formats.underline ? 'ql-active' : ''" class="iconfont icon-zitixiahuaxian" data-name="underline"></view><view :class="formats.strike ? 'ql-active' : ''" class="iconfont icon-zitishanchuxian" data-name="strike"></view><view :class="formats.align === 'left' ? 'ql-active' : ''" class="iconfont icon-zuoduiqi" data-name="align"data-value="left"></view><view :class="formats.align === 'center' ? 'ql-active' : ''" class="iconfont icon-juzhongduiqi" data-name="align"data-value="center"></view><view :class="formats.align === 'right' ? 'ql-active' : ''" class="iconfont icon-youduiqi" data-name="align"data-value="right"></view><view :class="formats.align === 'justify' ? 'ql-active' : ''" class="iconfont icon-zuoyouduiqi" data-name="align"data-value="justify"></view><view :class="formats.lineHeight ? 'ql-active' : ''" class="iconfont icon-line-height" data-name="lineHeight"data-value="2"></view><view :class="formats.letterSpacing ? 'ql-active' : ''" class="iconfont icon-Character-Spacing" data-name="letterSpacing"data-value="2em"></view><view :class="formats.marginTop ? 'ql-active' : ''" class="iconfont icon-722bianjiqi_duanqianju" data-name="marginTop"data-value="20px"></view><view :class="formats.previewarginBottom ? 'ql-active' : ''" class="iconfont icon-723bianjiqi_duanhouju" data-name="marginBottom"data-value="20px"></view><view class="iconfont icon-clearedformat" @tap="removeFormat"></view><view :class="formats.fontFamily ? 'ql-active' : ''" class="iconfont icon-font" data-name="fontFamily" data-value="Pacifico"></view><view :class="formats.fontSize === '24px' ? 'ql-active' : ''" class="iconfont icon-fontsize" data-name="fontSize"data-value="24px"></view><view :class="formats.color === '#0000ff' ? 'ql-active' : ''" class="iconfont icon-text_color" data-name="color"data-value="#0000ff"></view><view :class="formats.backgroundColor === '#00ff00' ? 'ql-active' : ''" class="iconfont icon-fontbgcolor"data-name="backgroundColor" data-value="#00ff00"></view><view class="iconfont icon-date" @tap="insertDate"></view><view class="iconfont icon--checklist" data-name="list" data-value="check"></view><view :class="formats.list === 'ordered' ? 'ql-active' : ''" class="iconfont icon-youxupailie" data-name="list"data-value="ordered"></view><view :class="formats.list === 'bullet' ? 'ql-active' : ''" class="iconfont icon-wuxupailie" data-name="list"data-value="bullet"></view><view class="iconfont icon-undo" @tap="undo"></view><view class="iconfont icon-redo" @tap="redo"></view><view class="iconfont icon-outdent" data-name="indent" data-value="-1"></view><view class="iconfont icon-indent" data-name="indent" data-value="+1"></view><view class="iconfont icon-fengexian" @tap="insertDivider"></view><view class="iconfont icon-charutupian" @tap="insertImage"></view><view :class="formats.header === 1 ? 'ql-active' : ''" class="iconfont icon-format-header-1" data-name="header":data-value="1"></view><view :class="formats.script === 'sub' ? 'ql-active' : ''" class="iconfont icon-zitixiabiao" data-name="script"data-value="sub"></view><view :class="formats.script === 'super' ? 'ql-active' : ''" class="iconfont icon-zitishangbiao" data-name="script"data-value="super"></view><view class="iconfont icon-shanchu" @tap="clear"></view><view :class="formats.direction === 'rtl' ? 'ql-active' : ''" class="iconfont icon-direction-rtl" data-name="direction"data-value="rtl"></view></view><view class="editor-wrapper"><editor id="editor" class="ql-container" placeholder="开始输入..." showImgSize showImgToolbar showImgResize@statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady" @input="getText"></editor></view></view></view></view>
</template><script>import url from '../../utils/api.js'export default {data() {return {readOnly: false,formats: {}}},methods: {readOnlyChange() {this.readOnly = !this.readOnly},onEditorReady() {console.log('00000000000000')uni.createSelectorQuery().select('#editor').context((res) => {this.editorCtx = res.contextconsole.log(this.editorCtx,'--------')}).exec()},getText(e){//获取数据var that = this;getApp().globalData.editor = e.detail.html// console.log(e.detail.html);//带标签内容// console.log(e.detail.text);//纯文本内容},undo() {this.editorCtx.undo()},redo() {this.editorCtx.redo()},format(e) {let {name,value} = e.target.datasetif (!name) return// console.log('format', name, value)this.editorCtx.format(name, value)},onStatusChange(e) {const formats = e.detailthis.formats = formats},insertDivider() {this.editorCtx.insertDivider({success: function() {console.log('insert divider success')}})},clear() {this.editorCtx.clear({success: function(res) {console.log("clear success")}})},removeFormat() {this.editorCtx.removeFormat()},insertDate() {const date = new Date()const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`this.editorCtx.insertText({text: formatDate})},insertImage() {var that = this;uni.chooseImage({count: 1,success: (res) => {console.log('insert image success')const tempFilePaths = res.tempFilePaths;uni.uploadFile({url: url.uploadimageEider,filePath: tempFilePaths[0],name: 'image',success: (uploadFileRes) => {let data=JSON.parse(uploadFileRes.data)console.log(data,"编辑详情的时候返回照片地址")var url=data.ip + data.data[0]if(data.errno=="0"){that.editorCtx.insertImage({src: url,alt: '图像',success: function() {}})}else{that.showToast(back.msg)}},fail:() =>{uni.hideLoading();that.showToast("图片上传失败,请联系开发!")}});}})}},onLoad() {uni.loadFontFace({family: 'Pacifico',source: 'url("https://sungd.github.io/Pacifico.ttf")'})},}
</script><style>@import "./editor-icon.css";.page-body {height: 800rpx;width: 733rpx;margin: 0 auto;border-radius: 12rpx;background-color: #FFFFFF;}.wrapper {height: 300rpx;}.editor-wrapper {background-color: #FFFFFF;height: 500rpx;}.iconfont {display: inline-block;padding: 8px 8px;width: 24px;height: 24px;cursor: pointer;font-size: 20px;}.toolbar {box-sizing: border-box;border-bottom: 0;font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;}.ql-container {box-sizing: border-box;padding: 12px 15px;width: 100%;min-height: 30vh;height: 100%;margin-top: 20px;font-size: 16px;line-height: 1.5;}.ql-active {color: #06c;}
</style>
uni-app的editor的富文本编辑器相关推荐
- vue使用ckeditor4富文本编辑器配置
使用场景: 本来最开始使用的是quill富文本编辑器,但是由于功能和项目得实际需求并不是怎么适合,因为我需要在Word文档里面把一些内容进行粘贴复制进去(复制的是图文),当出现这种场景的话quill就 ...
- N个富文本编辑器/基于Web的HTML编辑器
转自:http://www.cnblogs.com/lingyuan/archive/2010/11/15/1877447.html 基于WEB的HTML 编辑器,WYSIWYG所见即所得的编辑器,或 ...
- vue问题四:富文本编辑器上传图片
vue使用富文本编辑器上传图片: 我是用的是wangEditor 富文本编辑器 demo:http://www.wangeditor.com/ 1).安装依赖:npm install wangedit ...
- 富文本编辑器KindEditor在前端JS的应用
1.引入KindEditor资源包 2.页面引入Js,Css文件 3.html代码: <tr><td class="left">讲师信息</td> ...
- css wangeditor 修改_HTML富文本编辑器wangEditor的使用
var E = window.wangEditor; var editor = new E('#editor') //配置信息 var config = editor.customConfig; // ...
- 用DevExpress WinForms富文本编辑器,集成高级文本编辑功能(二)
DevExpress WinForm富文本编辑器(RTF编辑器)控件允许用户将高级文本编辑功能集成到下一个WinForms项目中,它包括全面的文本格式选项.支持邮件合并,并附带了丰富的终端用户选项集, ...
- 如何在富文本编辑器中实现自定义一键排版功能
前言 今天写这篇文章主要是解决如何在vue中使用富文本编辑器进行新增一个自定义菜单,通过富文本上传的图片实现一键排版功能使图片默认样式居中定宽处理,文字首行缩进等功能,从源头上杜绝门户网站上显示用户编 ...
- 富文本编辑器 vue-quill-editor使用(新增,展示,修改,添加附件相关)
上一篇文章链接 富文本编辑器 vue-quill-editor入门(使用,显示,表格支持) 之前由于自己也只是粗浅的使用,以为没有太多人和我一样用到它 有一些地方,就没有展开讲 没想到大家用到的还挺多 ...
- 百度富文本编辑器手机端预览插件开发
在百度富文本编辑器编辑的时候担心在手机端打开格式乱掉,编辑提交再去手机端刷新查看比较麻烦,希望在编辑器可以直接查看,效果如下: 下载文件: 链接: https://pan.baidu.com/s/1v ...
最新文章
- Java用for循环Map
- MySQL主主(双主)数据同步
- Arthas | 定位线上 Dubbo 线程池满异常
- hdu 2059(dp)
- SQL server CASE WHEN
- App-v Client的部署
- Node.js webpack 加载器
- 我发现:在StackOverflow上拯救歪果仁十分有意思!
- linux 第三章目录文件管理(上)
- 大数据相加_清华大学黄高——图像数据的语义层扩增方法
- 有目标就有动力!有目标就有意义!
- .net开发微信公众号(3)-接收微信推送的消息
- 在线超市系统-PythonGUI Tkinter 图片界面设计案例
- win10便签常驻桌面_在win10桌面上能显示日程表小工具的便签怎么使用?
- 年薪 10 万的程序员,如何积累人生的第一个 100 万?
- 代码赏析:子窗口对于键盘和鼠标的响应
- TCP缓冲区大小及限制
- C4D模型工具—优化
- 修改传奇私服服务器,传奇SF 肿么修改服务器时间
- Visio如何把形状置于底层
热门文章
- 七、ref引用与数组的常用方法
- 2021年中国鸡尾酒杯市场趋势报告、技术动态创新及2027年市场预测
- 学习《User and entity behavior analysis under urban big data》(UEBA)
- 混沌系统的matlab仿真可行性,超混沌系统的电路仿真及其自适应同步
- Kotlin只是一个“网红,【面试必备】
- 永磁直流电机 matlab仿真,永磁直流电动机的Simulink建模仿真优秀教学.doc
- 微信小程序点击事件失效
- 易代账好会计zip导入提示不平衡
- linux安装软件时/usr/lib/python2.7/site-packages/urlgrabber/grabber.py文件异常
- Logo Grabber 一键快速下载网站Logo 的免费插件