首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Quill编辑器不会在输入字段中显示v-模型(Vue 3)

Quill编辑器不会在输入字段中显示v-模型(Vue 3)
EN

Stack Overflow用户
提问于 2022-03-14 13:28:30
回答 2查看 1.6K关注 0票数 0

我想显示一些html,从quill editor内部的数据库中获取。html似乎很好(在<p>段落中显示),并通过v-model绑定到quill editor,但它只是没有显示:

代码语言:javascript
运行
复制
<template>
  <div id="text-editor" class="text-editor">
    <quill-editor :modules="modules" :toolbar="toolbar" v-model:content="store.re.body" contentType="html"/>
    <p>{{store.re.body}}</p>
  </div>
</template>


<script setup>
import BlotFormatter from 'quill-blot-formatter'
import store from "../../../js/store";

store.re.body = ''

const modules = {
    module: BlotFormatter,
}

const toolbar = [
    [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
    [{ 'size': ['small', false, 'large', 'huge'] }],
    ['bold', 'italic', 'underline', 'strike'],
    ['blockquote', 'code-block'],
    [{ 'align': [] }],
    [{ 'list': 'ordered'}, { 'list': 'bullet' }],
    [{ 'color': [] }, { 'background': [] }],
    [{ 'font': [] }],
    ['link', 'image', 'video'],
    ['clean']
];
</script>

这是从数据库(在另一个vue组件中)获取数据的地方:

代码语言:javascript
运行
复制
axios.get('/get-blog', {
        params: {
            id: state.id
        }
    })
    .then(res => {
        state.body = store.re.body = res.data[0].body
    })
    .catch(err => {
        state.error = true
        setTimeout(() => state.error = false, 5000)
    })

我使用store.re.body (反应性存储)将其传输到quill editor

store.js

代码语言:javascript
运行
复制
import {reactive} from "vue";

const re = reactive({})

export default {
    re
}

在这里您可以看到显示的editor page,下面是工作的<p>段落,但编辑器输入仍然是空的:

EN

Stack Overflow用户

发布于 2022-04-21 10:15:58

您应该尝试使用下面的示例

代码语言:javascript
运行
复制
    <script>
     import {QuillEditor} from "@vueup/vue-quill";
     export default {
       components: {
         QuillEditor, 
       },
 data(){
    return {
     someText:''
   }
}, 
   computed: {
     editor() {
      return this.$refs.quillEditor;
     },
   },
   methods: {
     getSetText() {
       this.someText = "<div><p>this is some text</p> </div>";
       this.editor.setHTML(this.someText);
      },
     }, 
   }
 </script>
代码语言:javascript
运行
复制
    <template><quill-editor ref="quillEditor" contentType="html"v-model:content="someText" theme="snow" ></quill-editor></template>

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71468563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档