hookehuyr

fix 富文本编辑器写入数据逻辑调整

<!--
* @Date: 2022-09-26 21:52:25
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-10-26 11:31:30
* @LastEditTime: 2022-10-26 18:54:14
* @FilePath: /swx/src/components/activity-editor.vue
* @Description: 文件描述
-->
......@@ -56,28 +56,41 @@ import { ref } from 'vue'
<script>
import Taro from '@tarojs/taro'
import BASE_URL from '@/utils/config';
import { activityInfoAPI } from '@/api/Host/index';
import { getCurrentPageParam } from "@/utils/weapp";
export default {
props: ['showTabBar', 'placeholder', 'name', 'htmlContent'],
data() {
return {
editorCtx: ''
editorCtx: '',
html_content: ''
}
},
watch: {
htmlContent (val) {
async htmlContent (val) {
// 如果有传值,还原重新编辑
this.editorCtx.setContents({
html: val
})
if (val) {
const { code, data } = await activityInfoAPI({ i: getCurrentPageParam().id });
if (code) {
// 更新活动信息
this.html_content = data.activity.note
this._onEditorReady()
}
}
}
},
methods: {
_onEditorReady: function () {
const that = this;
Taro.createSelectorQuery().select('#editor').context(function (res) {
that.editorCtx = res.context
}).exec();
setTimeout(() => {
wx.createSelectorQuery().select('#editor').context(function (res) {
that.editorCtx = res.context;
that.editorCtx.setContents({
html: that.html_content //将数据写入编辑器内
})
}).exec();
}, 500);
},
//插入图片
_addImage: function (event) {
......@@ -160,6 +173,12 @@ export default {
// this.triggerEvent("input", { html: html, text: text }, {});
// console.warn(html);
// console.warn(text);
},
_rewrite (val) {
// 如果有传值,还原重新编辑
this.editorCtx.setContents({
html: val
})
}
}
}
......