单击vue中的按钮时,如何将Quill Text Editor读取
我有一个Quill文本编辑器,默认情况下,我想将其设置为ReadOnly,当单击按钮时,这应该是TRUE/FALSE。因此,这是我的组成部分:
<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: {
disabled: { type: Boolean, default: false },
value: {
type: String,
default: ''
}
},
data() {
return {
editor: null,
};
},
mounted() {
this.editor = new Quill(this.$refs.editor, {
modules: {
toolbar: [
[{ header: [1, 2, 3, 4, false] }],
['bold', 'italic', 'underline']
]
},
readOnly: this.disabled,
theme: 'snow',
formats: ['bold', 'underline', 'header', 'italic']
});
this.editor.root.innerHTML = this.value;
this.editor.on('text-change', () => this.update());
},
methods: {
update() {
this.$emit('input', this.editor.getText() ? this.editor.root.innerHTML : '');
}
}
}
</script>
我将此值作为“禁用”的组件发送给我的组件,当我单击按钮时,true变为false,当我再次单击Visa Versa时。因此,这没什么错。另外,当我确实读取:true或Readonly:false时,它有效,但是使用这种方式,可读取:this.disabled它无效。
我正在使用vue,但我直接基于quilljs创建了一个组件。
I have a quill text editor and as a default I want to set it as readonly and when the button is clicked, this should be true/false. So here is my component:
<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: {
disabled: { type: Boolean, default: false },
value: {
type: String,
default: ''
}
},
data() {
return {
editor: null,
};
},
mounted() {
this.editor = new Quill(this.$refs.editor, {
modules: {
toolbar: [
[{ header: [1, 2, 3, 4, false] }],
['bold', 'italic', 'underline']
]
},
readOnly: this.disabled,
theme: 'snow',
formats: ['bold', 'underline', 'header', 'italic']
});
this.editor.root.innerHTML = this.value;
this.editor.on('text-change', () => this.update());
},
methods: {
update() {
this.$emit('input', this.editor.getText() ? this.editor.root.innerHTML : '');
}
}
}
</script>
I am sending this value as a prop to my component which is 'disabled' and when I click the button true becomes false and when I click again visa versa. So there is nothing wrong with that. Also when I do readOnly: true, or readOnly: false it works but with this way, readOnly: this.disabled it doesnt work.
I am using vue but I created a component based on quilljs directly.
The documentation I use is this one: https://quilljs.com/docs/configuration/#readonly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题,并且有一个“ [Vue警告]:试图突变“启用”。道具是阅读的。尝试更改组件中的道具时。您可以将“启用”或“禁用”道具传递给羽毛笔,取决于按钮条件,然后重新固定鹅毛笔组件。
另外,您可以使用此。
I have a same problem and have a "[Vue warn]: Attempting to mutate prop "enable". Props are readonly." message when try to change props in component. You can pass "enable" or "disable" props to quill depends of button conditions and then reinit Quill component.
also you can use this.$refs.myEditor.getQuill().enable(true) to set active and this.$refs.myEditor.getQuill().enable(false) to unactivate write option.