如何将Quill Text Editor用作vue.js中的组件
我在这里看到的是VUE中的Quill Text Editor作为组件:
<template>
<div ref="editor"></div>
</template>
<script>
import Quill from 'quill';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.bubble.css';
import 'quill/dist/quill.snow.css';
export default {
props: {
value: {
type: String,
default: ''
}
},
data() {
return {
editor: null
};
},
mounted() {
var _this = this;
this.editor = new Quill(this.$refs.editor, {
modules: {
toolbar: [[{
header: [1, 2, 3, 4, false]
}], ['bold', 'italic', 'underline', 'link']]
},
//theme: 'bubble',
theme: 'snow',
formats: ['bold', 'underline', 'header', 'italic', 'link'],
placeholder: "Type something in here!"
});
this.editor.root.innerHTML = this.value;
this.editor.on('text-change', function () {
return _this.update();
});
},
methods: {
update: function update() {
this.$emit('input', this.editor.getText() ? this.editor.root.innerHTML : '');
}
},
}
</script>
因此,它是基本的Quill组件,我使用Quill 1.3.7。对于文档: https://quilljs.com/
因此,在父母的组件中,我创建了V-Model,以查看以查看此组件的结果:
<text-editor
v-model="model"/>
<p> <span v-html="model"></span></p>
但是不幸的是,我没有任何响应,也没有错误。您认为我做错了什么?
I created quill text editor as a component in vue as you can see here:
<template>
<div ref="editor"></div>
</template>
<script>
import Quill from 'quill';
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.bubble.css';
import 'quill/dist/quill.snow.css';
export default {
props: {
value: {
type: String,
default: ''
}
},
data() {
return {
editor: null
};
},
mounted() {
var _this = this;
this.editor = new Quill(this.$refs.editor, {
modules: {
toolbar: [[{
header: [1, 2, 3, 4, false]
}], ['bold', 'italic', 'underline', 'link']]
},
//theme: 'bubble',
theme: 'snow',
formats: ['bold', 'underline', 'header', 'italic', 'link'],
placeholder: "Type something in here!"
});
this.editor.root.innerHTML = this.value;
this.editor.on('text-change', function () {
return _this.update();
});
},
methods: {
update: function update() {
this.$emit('input', this.editor.getText() ? this.editor.root.innerHTML : '');
}
},
}
</script>
So it is a basic quill component and I use quill 1.3.7. For the documentation: https://quilljs.com/
So in the parent component I created v-model to see the result of this component:
<text-editor
v-model="model"/>
<p> <span v-html="model"></span></p>
But unfortunately I dont get any response and no error either. What do you think I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使您将问题标记为a vue 2 问题,我猜想您正在使用 vue 3 ,因为否则,它应该可以正常工作(我也尝试了您的代码并将其修复在Vue 3)。
您实际上是在面对破坏变化问题。 >
现在要使用V模型更新数据时,需要使用:
您的代码应该看起来像这样!
对于VUE 3:
您的项目祝您好运,
Even though you tagged the question as a Vue 2 question, I am going to guess you are using Vue 3 because otherwise, it should work just fine (I also tried your code and fixed it on Vue 3).
You are actually facing a breaking change issue.
When you want to update your data with a v-model now, you need to use :
Your code should look like this for Vue 3 :
Good luck with your project!