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

完成!

相关推荐
柳杉3 分钟前
从数字化到数智化:3D 可视化大屏的下一个五年
前端·ai编程·数据可视化
风骏时光牛马1 小时前
从零到实战:AI全栈学习进阶路线
前端
FRing031 小时前
JavaScript入门到精通二十六(变量提升、函数剩余参数、展开运算符、ES6箭头函数)
开发语言·前端·javascript·es6·箭头函数
用户360055579001 小时前
Kestrel_VLLM - 15 · decode 优化四连击:19ms → 8ms
前端
IT_陈寒2 小时前
JavaScript的闭包陷阱,这个坑我躺了三天才爬出来
前端·人工智能·后端
计算机魔术师2 小时前
Microsoft Research 与合作者证明 31 年历史的 KLS 猜想
前端
weixin_417396832 小时前
桌面云终端PXE启动失败怎么排查?从DHCP Option到镜像下发
开发语言·前端·php·技术·酒店·综合布线·弱电
林恒smileZAZ2 小时前
浏览器为什么加载不了超大图片
前端·vue.js·html5
hhwyqwqhhwy3 小时前
设备树之 provider 和 consumer
java·linux·前端
垆边人似月.4 小时前
Python中如何使用get函数实现频次查询
服务器·前端·python