想要的样式:
let content = ref("<p> 初始内容。。。</p>");报红的原因
今天在敲文本时,content报错了
这里该如何解决:
第一个解决的方法,富文本编辑器中这里必须的script中添加setup
第二个 export中再使用的时候,必须要添加第二个script
第三个 看绑定数据,下一步
看绑定数据的资料:
这里注意要添加content
添加v-model,这里要注意content添加的内容
代码:
<template> <div class="editorContainer"> <el-form ref="ruleFormRef" style="max-width: 900px" :model="ruleForm" :rules="rules" label-width="auto" class="demo-ruleForm" :size="formSize" status-icon> <el-form-item label="标题" prop="name"> <el-input v-model="ruleForm.name" /> </el-form-item> <div class="editorContent"> <div class="leftcontentContainer">内容</div> <div class="editor"> <quill-editor content-type='html' v-model:content='articleModel.content' :options='options' @blur='editorBlur($event)' /> <!-- <quill-editor content-type='html' :content='content' :options='options' @blur='editorBlur($event)' /> --> <!-- <quill-editor content-type='html' :content='content' :options='options' @blur='editorBlur($event)' /> --> </div> </div> <div class="mb-4"> <el-button round>保存</el-button> <el-button type="primary" round>提交</el-button> </div> </el-form> </div> </template> <script setup> // import { ref } from 'vue'; // let content = ref("<p> 初始内容。。。</p>"); let options = { modules: { toolbar: [ ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线 [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色 [{ align: [] }], // 对齐方式 [{ size: ['small', false, 'large', 'huge'] }], // 字体大小 [{ font: [] }], // 字体种类 [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题 [{ direction: 'ltl' }], // 文本方向 [{ direction: 'rtl' }], // 文本方向 [{ indent: '-1' }, { indent: '+1' }], // 缩进 [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表 [{ script: 'sub' }, { script: 'super' }], // 上标/下标 ['blockquote', 'code-block'], // 引用 代码块 ['clean'], // 清除文本格式 ['link', 'image', 'video'], // 链接、图片、视频 ], }, }; </script> <script> export default { data() { return { ruleForm: [{ name: '' }], articleModel: [{ content: '' }] } } } </script> <style lang="less"> .demo-ruleForm { margin: 0 auto; } .div span { text-align: left; } .editorContent { display: flex; } .editorContainer { margin-top: 15px; } .leftcontentContainer { margin-right: 9px; } .editor { width: 857px; margin-bottom: 60px; } .ql-container { height: 400px; } .demo-ruleForm { width: 1000px; } .mb-4 button { margin: 0 0 0 760px; } </style>