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>

相关推荐
我叫张小白。4 分钟前
Vue3 Hooks:逻辑复用的解决方案
前端·javascript·vue.js·前端框架·vue
S***t7148 分钟前
前端物联网开发
前端·物联网
我叫张小白。15 分钟前
Vue3 Props 的使用:组件间数据传递的桥梁
前端·javascript·vue.js·vue3
r***869816 分钟前
Nginx解决前端跨域问题
运维·前端·nginx
广州华水科技23 分钟前
单北斗GNSS在桥梁变形监测中的关键应用与技术优势分析
前端
IT_陈寒24 分钟前
Python 3.12新特性实战:10个让你效率翻倍的代码优化技巧
前端·人工智能·后端
z***948425 分钟前
Redis 6.2.7安装配置
前端·数据库·redis
2301_8072886326 分钟前
MPRPC项目制作(第四天)
java·服务器·前端
J***793927 分钟前
前端在移动端中的React Native Windows
前端·react native·react.js
阿雄不会写代码27 分钟前
PPTX报错AttributeError: module ‘collections‘ has no attribute ‘Container‘
前端