https://developers.weixin.qq.com/miniprogram/dev/component/editor.html 富文本组件文档
// 点击图片将图片插入富文本编辑器里面
insertImage() {
const that = this;
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
console.log(res.tempFilePaths,'上传图片')
wx.uploadFile({
url: '自己的图片上传地址',
filePath: res.tempFilePaths[0],
name: 'file',
formData: {
app_token: app.data.userInfo.app_token,
},
success: function (res) {
console.log(res.data,'图片上传之后的数据')
var data = JSON.parse(res.data)
console.log(data.data.url)
that.editorCtx.insertImage({
src: data.data.url,
success: function () {
console.log('insert image success')
}
})
}
})
}
})
}
//初始化富文本编辑器方法
onEditorReady() {
const that = this
wx.createSelectorQuery().select('#editor').context(function (res) {
that.editorCtx = res.context
that.loadData();//这里拉取需要编辑的数据然后初始化到编辑器里面
}).exec()
},
//初始化富文本编辑器方法
that.editorCtx.setContents({
html: '这里放接口返回的富文本标签数据',
success: function () {
console.log('insert html success')
}
})