uni-app editor 简单实用富文本

需求,简单的复制文字、有格式 ,能从别的地方复制文案过来,有格式化展示即可,要求高的可以去插件市场看看。

可以直接复制允许!!!! 前提是在项目里!!!

<template>

<view class="container">

<view class="editor-wrapper">

<editor id="editor" class="ql-container" placeholder="开始输入..." show-img-size show-img-toolbar

show-img-resize @ready="onEditorReady" @input="onEditorInput">

</editor>

</view>

</view>

</template>

<script>

export default {

data() {

return {

editorCtx: null,

isDataLoad: false, //仅初始化 加载时使用,例如编辑

}

},

onLoad() {

this.loadActivityDetail()

},

methods: {

onEditorReady() {

uni.createSelectorQuery().select('#editor').context((res) => {

console.log('===>', res)

this.editorCtx = res.context

// 初始化测试 假的

this.editorCtx.setContents({

html: 'zouni~~~'

})

}).exec()

},

onEditorInput(e) {

this.editorContext = e.detail.html

// console.log('编辑器内容发生变化:', e.detail.html);

},

// 初始化 走接口加载数据

setEditorContents() {

if (this.isDataLoad) {

this.editorCtx.setContents({

html: this.editorContext, //editorContext 后台返回的数据

success: res => {}

})

} else {

// isDataLoad false 就一直调用,因为我这边内容一定有,没有可以不用

setTimeout(() => {

this.setEditorContents()

}, 200)

}

},

async loadActivityDetail(activityId) {

await this.$u.api

.activityDetail(activityId)

.then((res) => {

this.editorContext = res.data.description

this.isDataLoad = true

// 调用更新 富文本内容 初始化

this.setEditorContents()

})

.catch((err) => {

console.log(err);

});

},

}

}

</script>

相关推荐
kyriewen12 小时前
我手写了一个 EventEmitter,面试官追问了 6 个问题——第 4 个我没答上来
前端·javascript·面试
IT_陈寒12 小时前
Java的Date类又坑了我一次,改用时间戳真香
前端·人工智能·后端
小林攻城狮13 小时前
使用 Transport 节流解决 Vercel AI SDK 流式渲染卡死问题
前端·react.js
前端缘梦13 小时前
告别 TS 运行时类型漏洞!Zod 完整入门实战教程(前端 / 全栈必备)
前端·react.js·全栈
the_answer13 小时前
Webpack vs Vite 深度对比分析
前端·webpack
转转技术团队13 小时前
验证码识别实战:前端不写页面,改训模型了?
前端
MomentYY13 小时前
Temperature:AI 的“脑洞旋钮”
前端·llm·ai编程
远航_14 小时前
OpenSpec 完整详细介绍
前端·后端
召钱熏14 小时前
状态枚举正确≠渲染正确:一个语音按钮的状态机边界修复实录
android·前端
SkyWalking中文站14 小时前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控