提交 2b1d4778 编写于 作者: 刘英杰's avatar 刘英杰

测试提交

上级 b9ae30a7
<template> <template>
<div class="i-quill" :class="classes"> <div class="i-quill" :class="classes">
<div ref="editor" :style="styles"></div> <div ref="editor" :style="styles"></div>
<div></div>
</div> </div>
</template> </template>
<script> <script>
import Quill from 'quill'; import Quill from 'quill';
import 'quill/dist/quill.core.css'; import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css'; import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css'; import 'quill/dist/quill.bubble.css';
export default { export default {
name: 'i-quill', name: 'i-quill',
props: { props: {
value: { value: {
...@@ -28,7 +29,7 @@ ...@@ -28,7 +29,7 @@
type: Number type: Number
} }
}, },
data () { data() {
return { return {
Quill: null, Quill: null,
currentValue: '', currentValue: '',
...@@ -39,34 +40,34 @@ ...@@ -39,34 +40,34 @@
modules: { modules: {
toolbar: [ toolbar: [
['bold', 'italic', 'underline', 'strike'], ['bold', 'italic', 'underline', 'strike'],
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{'header': [1, 2, 3, 4, 5, 6, false]}],
[{ 'size': ['small', false, 'large', 'huge'] }], [{'size': ['small', false, 'large', 'huge']}],
[{ 'color': [] }, { 'background': [] }], [{'color': []}, {'background': []}],
['blockquote', 'code-block'], ['blockquote', 'code-block'],
[{ 'list': 'ordered' }, { 'list': 'bullet' }], [{'list': 'ordered'}, {'list': 'bullet'}],
// [{ 'script': 'sub' }, { 'script': 'super' }], // [{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }], [{'indent': '-1'}, {'indent': '+1'}],
[{ 'align': [] }], [{'align': []}],
[{ 'direction': 'rtl' }], [{'direction': 'rtl'}],
// [{ 'font': [] }], // [{ 'font': [] }],
['clean'], ['clean'],
['link', 'image'] ['link',]
] ]
}, },
placeholder: '内容...', placeholder: '请输入竞赛公告内容...',
readOnly: false readOnly: false
} }
} }
}, },
computed: { computed: {
classes () { classes() {
return [ return [
{ {
'i-quill-no-border': !this.border 'i-quill-no-border': !this.border
} }
]; ];
}, },
styles () { styles() {
let style = {}; let style = {};
if (this.minHeight) { if (this.minHeight) {
style.minHeight = `${this.minHeight}px`; style.minHeight = `${this.minHeight}px`;
...@@ -79,9 +80,10 @@ ...@@ -79,9 +80,10 @@
}, },
watch: { watch: {
value: { value: {
handler (val) { handler(val) {
if (val !== this.currentValue) { if (val !== this.currentValue) {
this.currentValue = val; this.currentValue = val;
if (this.Quill) { if (this.Quill) {
this.Quill.pasteHTML(this.value); this.Quill.pasteHTML(this.value);
} }
...@@ -91,7 +93,7 @@ ...@@ -91,7 +93,7 @@
} }
}, },
methods: { methods: {
init () { init() {
const editor = this.$refs.editor; const editor = this.$refs.editor;
// 初始化编辑器 // 初始化编辑器
this.Quill = new Quill(editor, this.options); this.Quill = new Quill(editor, this.options);
...@@ -106,8 +108,9 @@ ...@@ -106,8 +108,9 @@
this.currentValue = html; this.currentValue = html;
// 发出事件 v-model // 发出事件 v-model
this.$emit('input', html); this.$emit('input', html);
this.$emit('setRichTextValue', html);
// 发出事件 // 发出事件
this.$emit('on-change', { html, text, quill }); this.$emit('on-change', {html, text, quill});
}); });
// 将一些 quill 自带的事件传递出去 // 将一些 quill 自带的事件传递出去
this.Quill.on('text-change', (delta, oldDelta, source) => { this.Quill.on('text-change', (delta, oldDelta, source) => {
...@@ -121,23 +124,24 @@ ...@@ -121,23 +124,24 @@
}); });
} }
}, },
mounted () { mounted() {
this.init(); this.init();
}, },
beforeDestroy () { beforeDestroy() {
// 在组件销毁后销毁实例 // 在组件销毁后销毁实例
this.Quill = null; this.Quill = null;
} }
} }
</script> </script>
<style lang="less"> <style lang="less">
.i-quill-no-border{ .i-quill-no-border {
.ql-toolbar.ql-snow{ .ql-toolbar.ql-snow {
border: none; border: none;
border-bottom: 1px solid #e8eaec; border-bottom: 1px solid #e8eaec;
} }
.ql-container.ql-snow{
.ql-container.ql-snow {
border: none; border: none;
} }
} }
</style> </style>
Markdown 格式
0% or
您添加了 0 人 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册 或