uniapp中使用编辑器editor

1.需求:

开发小程序时,想要在手机上添加编辑内容,使用u--textarea时,换行操作不显示,为此使用了uniapp自带的组件editor来实现:

2.使用:

html 复制代码
<template>
	<view class="">
		<!-- <u--textarea v-model="content" placeholder="请输入活动地址..." maxlength='-1'></u--textarea> -->
		<editor id="editor" class="ql-container m-ql-container" placeholder="请输入活动地址和详细的活动介绍..."
				@ready="onEditorReady" @input="getEditorContent">
		</editor>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
			}
		},
	
		methods: {
			//1.初始化编辑器
			onEditorReady() { 
				//将content是从后台获取的字符串,将字符串转化为delta对象
				setTimeout(() => {
					var htmls = this.content
					console.log(htmls)
					if (htmls) {
						let contents = JSON.stringify(htmls)
						console.log(contents)
						uni.createSelectorQuery().select('#editor').context((res) => {
							console.log(res);
							let con = res.context
							con.setContents({
								html: htmls,
								delta: contents
							})
						}).exec()
					} else {
						return
					}
				}, 500)
			},
			//2.获取编辑器内容,当前页面都能获取到
			getEditorContent(e) { 
				this.content = e.detail.html;
			},
			
		}
	}
</script>

<style scoped>
	#editor {
		width: 100%;
		height: 300px;
		margin-top:10px;
	}
</style>

具体可参考官网:https://uniapp.dcloud.net.cn/component/editor.html

完成!

相关推荐
问心无愧051316 小时前
ctf show web入门160 161
前端·笔记
李小白6616 小时前
第四天-WEB服务器基本原理,IIS服务
运维·服务器·前端
humcomm17 小时前
AI编程时代新前端职位
前端·ai编程
好家伙VCC17 小时前
Web Components主题热切换方案揭秘
java·前端
甲维斯17 小时前
Kimi版超级玛丽效果“惊人”,配额不足5厘米!
前端·人工智能
hboot17 小时前
AI工程师第一课 - Python
前端·后端·python
凉菜凉凉17 小时前
AI时代,被抛弃的前端
前端·ai
console.log('npc')18 小时前
AI前端工程与生成式UI学习路线
前端·人工智能·ui
梦曦i18 小时前
uni-router v1.1.1发布:守卫超时保护+路由监听
前端·uni-app
qq_25183645718 小时前
基于java Web网络订餐系统设计与实现 源码文档
java·开发语言·前端