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>

相关推荐
2601_958492556 小时前
Optimizing Engagement with Freehead Skate - HTML5 Game - Construct 3
前端·html·html5
茉莉玫瑰花茶7 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
zhangxingchao8 小时前
AI应用开发六:企业知识库
前端·人工智能·后端
山峰哥8 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘
前端·数据库·sql·性能优化
红尘散仙8 小时前
一个 `#[uniffi::export]`,把 Rust 接进 React Native
前端·后端·rust
moshuying8 小时前
AI Coding 最大的 token 黑洞,可能根本不是 prompt
前端
红尘散仙8 小时前
一行 `#[specta::specta]`,让 Tauri IPC 有类型
前端·后端·rust
lichenyang4539 小时前
HarmonyOS HMRouter 接入记录:从普通 Tab Demo 到路由跳转
前端
木斯佳9 小时前
前端八股文面经大全:腾讯WXG暑期前端一面(2026-05-15)·面经深度解析
前端·面试·笔试