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>

相关推荐
懂懂tty7 小时前
React状态更新流程
前端·react.js
小码哥_常7 小时前
告别繁琐!手把手教你封装超实用Android原生Adapter基类
前端
skywalk81637 小时前
pytest测试的时候这是什么意思?Migrating <class ‘kotti.resources.File‘>
前端·python
一只蝉nahc8 小时前
vue使用iframe内嵌unity模型,并且向模型传递信息,接受信息
前端·vue.js·unity
子兮曰8 小时前
Bun v1.3.12 深度解析:新特性、性能优化与实战指南
前端·typescript·bun
2401_885885049 小时前
易语言彩信接口怎么调用?E语言Post实现多媒体数据批量下发
前端
a1117769 小时前
Three.js 的前端 WebGL 页面合集(日本 开源项目)
前端·javascript·webgl
Kk.08029 小时前
项目《基于Linux下的mybash命令解释器》(一)
前端·javascript·算法
小李子呢021110 小时前
前端八股---闭包和作用域链
前端
IT_陈寒11 小时前
Redis的内存溢出坑把我整懵了,分享这个血泪教训
前端·人工智能·后端