编辑器wxml

<view class="container" style="height:{{editorHeight}}px;"><editor id="editor" class="ql-container" placeholder="{{placeholder}}" bindstatuschange="onStatusChange" bindready="onEditorReady"></editor>
</view><scroll-view scroll-x ="{{true}}"><view class="toolbar" catchtouchend="format" hidden="{{keyboardHeight > 0 ? false : true}}" style="bottom: {{isIOS ? keyboardHeight : 0}}px"><i class="iconfont icon-charutupian" catchtouchend="insertImage"></i><i class="iconfont icon-format-header-1 {{formats.header === 1 ? 'ql-active' : ''}}" data-name="header" data-value="{{1}}"></i><i class="iconfont icon-format-header-2 {{formats.header === 2 ? 'ql-active' : ''}}" data-name="header" data-value="{{2}}"></i><i class="iconfont icon-format-header-3 {{formats.header === 3 ? 'ql-active' : ''}}" data-name="header" data-value="{{3}}"></i><i class="iconfont icon-zitijiacu {{formats.bold ? 'ql-active' : ''}}" data-name="bold"></i><i class="iconfont icon-zitixieti {{formats.italic ? 'ql-active' : ''}}" data-name="italic"></i><i class="iconfont icon-zitixiahuaxian {{formats.underline ? 'ql-active' : ''}}" data-name="underline"></i><i class="iconfont icon--checklist" data-name="list" data-value="check"></i><i class="iconfont icon-youxupailie {{formats.list === 'ordered' ? 'ql-active' : ''}}" data-name="list" data-value="ordered"></i><i class="iconfont icon-wuxupailie {{formats.list === 'bullet' ? 'ql-active' : ''}}" data-name="list" data-value="bullet"></i><i class="iconfont icon-clearedformat" bindtap="removeFormat"></i><i class="iconfont icon-shanchu" bindtap="clear"></i><i class="iconfont icon-undo" bindtap="undo"></i><i class="iconfont icon-redo" bindtap="redo"></i><i class="iconfont icon-date" bindtap="redo"></i></view>
</scroll-view>

editor.js

Page({data: {formats: {},readOnly: false,placeholder: '在这里尽情创作吧!',editorHeight: 300,keyboardHeight: 0,isIOS: false},readOnlyChange() {this.setData({readOnly: !this.data.readOnly})},onLoad() {const platform = wx.getSystemInfoSync().platformconst isIOS = platform === 'ios'this.setData({ isIOS})const that = thisthis.updatePosition(0)let keyboardHeight = 0wx.onKeyboardHeightChange(res => {if (res.height === keyboardHeight) returnconst duration = res.height > 0 ? res.duration * 1000 : 0keyboardHeight = res.heightsetTimeout(() => {wx.pageScrollTo({scrollTop: 0,success() {that.updatePosition(keyboardHeight)that.editorCtx.scrollIntoView()}})}, duration)})},updatePosition(keyboardHeight) {const toolbarHeight = 50const { windowHeight, platform } = wx.getSystemInfoSync()let editorHeight = keyboardHeight > 0 ? (windowHeight - keyboardHeight - toolbarHeight) : windowHeightthis.setData({ editorHeight, keyboardHeight })},calNavigationBarAndStatusBar() {const systemInfo = wx.getSystemInfoSync()const { statusBarHeight, platform } = systemInfoconst isIOS = platform === 'ios'const navigationBarHeight = isIOS ? 44 : 48return statusBarHeight + navigationBarHeight},onEditorReady() {const that = thiswx.createSelectorQuery().select('#editor').context(function (res) {that.editorCtx = res.context}).exec()},blur() {this.editorCtx.blur()},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.setData({ formats })},insertDivider() {this.editorCtx.insertDivider({success: function () {console.log('insert divider success')}})},clickLogText(e) {that.editorCtx.getContents({success: function (res) {console.log(res.html)wx.setStorageSync("content", res.html); // 缓存本地console.log(res.html)}})},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() {const that = thiswx.chooseImage({count: 1,success: function (res) {that.editorCtx.insertImage({src: res.tempFilePaths[0],data: {id: 'abcd',role: 'god'},width: '100%',success: function () {console.log('insert image success')}})}})}
})

使用微信小程序editor富文本编辑器(爬坑要点)相关推荐

  1. uniapp 微信小程序 editor富文本编辑器 api 使用记录

    文章目录 1.查看官方示例 2.关于富文本编辑器的工具栏 3.自己实践一下 效果 这里记录一下自己研究学习的结果 之前一直使用textarea 来进行内容的编辑.但是局限性还是太多,最近发现了edit ...

  2. 小程序editor 富文本编辑器组件

    效果: 关于editor 富文本编辑器组件 复制到组件common 里面.json 引用即可 链接:https://pan.baidu.com/s/1_QIp28IOVuyVFfKfFZwxKQ 提取 ...

  3. 云开发小程序editor富文本编辑器上传图片实现增删改

    在做一个博客小程序,用的是云开发,用editor编辑器上传图片,一开始直接传图片会出现真机不显示的情况,排查原因后发现是因为传入的是本地路径,而小程序要求的是https或者云id,于是做了以下修改:先 ...

  4. 微信小程序教程-富文本编辑器editor

    效果图: 1.首先进入官方文档的editor地址 https://developers.weixin.qq.com/miniprogram/dev/component/editor.html 2.可点 ...

  5. 微信小程序实现富文本编辑器

    1.参考官方文档:editor | 微信开放文档 在文档最下方有示例代码,如下图:   点击"在开发者工具中预览效果" 2.将示例代码保存至桌面,以便后期操作 3.文件夹中有一下文 ...

  6. 微信小程序接收富文本编辑器图片大小解决方法

    一.先上案列: 1.图片没有尺寸影响整体布局 二.改完之后: 三.上代码展示 1.wxml <!--pages/articleInfo/articleInfo.wxml--> <vi ...

  7. 微信小程序端富文本输入

    有个需求是用户端也就是小程序端,需要可以富文本发布文章. 示例: 1. 下载组件-微信小程序editor富文本编辑器组件 2.放在小程序自定义组件文件夹下 3.需要用到的页面引入该组件 "u ...

  8. 小程序(二十六)微信小程序解析富文本的几种方式

    微信小程序解析富文本html大概有两种方式(我发现的). 两种方法,各有各的优缺点. 一:使用小程序内置标签rich-text 这个标签解析的富文本会保留你在pc端编辑的样式,也就是说,你在pc端编辑 ...

  9. 微信小程序rich-text富文本图片

    背景: 本地做微信小程序项目,后台通过富文本编辑器编辑内容,在小程序页面展示时使用rich-text遇到了图片不能展示和图片尺寸过大的问题. 问题一:富文本编辑器中的图片无法展示 <rich-t ...

最新文章

  1. R语言常用sys函数汇总:sys.chmod、Sys.Date、Sys.time、Sys.getenv、Sys.getlocale、sys.getpid、sys.glob、sys.info等
  2. 推荐系统笔记:使用分类模型进行协同过滤
  3. css 边框设置成不透明,css中如何设置半透明边框?
  4. H5新增API_geoLocation
  5. 【转载】LinkedHashMap和HashMap区别
  6. 我爱计算机视觉干货集锦分类汇总(2019年6月17日)
  7. [转载] numpy逆 python_Python之Numpy详细教程,附Python最新学习资料
  8. c++类之间的基本关系
  9. JDK1.8优雅的集合排序(集合的排序)
  10. 辨别身份真假之【天眼数聚】腾讯云身份证实名认证接口
  11. Mbit/s vs MB/s vs MiB/s
  12. vb ajax提交post,使用jQuery AJAX将JS数组传递给VB.Net post
  13. Python 网站开发(一)环境搭建
  14. 台式计算机cpu功率,如何计算主机所需的功率? ?
  15. 七麦js破解(最新)
  16. 3.2 有界线性泛函及其表示 有限维赋范线性空间
  17. 计算机多用户访问控制软件,Win10权限管理与多用户远程登录(多方案)
  18. 关于如何搭建网站并发布上线
  19. Android MPU6500r添加
  20. 做外汇投资交易为何大家都钟爱MT4软件

热门文章

  1. python打开paint并画一个圆
  2. 不同的「火」在舌頭上的表現也不一樣
  3. JavaScript图片缩放库Zooming
  4. 简述现代计算机系统的层次结构,计算机系统结构简述.doc
  5. HTML5+WebGL 3D机房开发实例
  6. 是寒冬还是风口?2015年HTML5游戏完整产业链报告
  7. 自媒体怎么赚钱!自媒体怎么做收益比较高!
  8. 读书笔记:《枪炮、病菌与钢铁》与《1984》
  9. Oracle 执行计划(Explain Plan)
  10. java虚拟机参数 -D、-X和-XX的区别