网站文章内容编辑器(从小程序的利用富文本编辑器editor添加文章,上传图片 )
优采云 发布时间: 2022-03-20 07:12网站文章内容编辑器(从小程序的利用富文本编辑器editor添加文章,上传图片
)
从小程序使用富文本编辑器添加文章,上传图片,到使用富文本编辑器编辑已有的文章,
我开始考虑将文章阅读页面中按钮的参数id携带到编辑页面。编辑页面从onload中的options中获取文章id,然后在onEditorReady()中请求服务器获取文章内容,放入编辑器进行编辑。后来觉得不对,没必要再请求服务器了。
所以,在 文章 页面上,使用 isme 和 isadmin,如果是其中之一,就会显示编辑按钮。按钮跳转到编辑页面,使用getcurrentpage获取文章页面的数据,放入编辑器中。
onEditorReady() {
// 没必要再去服务端请求数据
var that = this
var pages = getCurrentPages();
var prevPage = pages[pages.length - 2];
// var getData = wx.request({//没必要再去服务端请求
wx.createSelectorQuery().select('#editor').context(function(res) {
that.editorCtx = res.context
that.editorCtx.setContents({
html: prevPage.data.articlecontent,//这里就是获取上一页面中的数据
success: (res) => {
console.log(res)
},
fail: (res) => {
console.log(res)
}
})
}).exec()
that.setData({
content: prevPage.data.articlecontent,//假如用户没有点击内容,则用这个内容
title: prevPage.data.leassonTilte,//假如用户没有点击标题,则用这个标题
titleCount: prevPage.data.leassonTilte.length
})
},