1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
| <template>
| <div>
| <quill-editor
| class="editor"
| v-model="content"
| ref="quillEditor"
| :options="editorOptions"
| ></quill-editor>
| </div>
| </template>
|
| <script>
| const toolbarOptions = [
| ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
| ['blockquote', 'code-block'], // 引用 代码块
| [{ header: 1 }, { header: 2 }], // 1、2 级标题
| [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
| [{ script: 'sub' }, { script: 'super' }], // 上标/下标
| [{ indent: '-1' }, { indent: '+1' }], // 缩进
| // [{'direction': 'rtl'}], // 文本方向
| [{ size: ['small', false, 'large', 'huge'] }], // 字体大小
| [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
| [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
| [{ font: [] }], // 字体种类
| [{ align: [] }], // 对齐方式
| ['clean'], // 清除文本格式
| // ['link', 'image', 'video'] // 链接、图片
| ['link', 'image'] // 链接、图片
| ]
| export default {
| name:'test',
| data() {
| return {
| content: '',
| editorOptions: {
| // Quill编辑器的选项
| placeholder: '请输入内容!',
| modules:{
| toolbar:{
| container:toolbarOptions
| }
| }
|
| }
| };
| },
| mounted() {
| let self = this;
| const editor = this.$refs.quillEditor.quill;
| const toolbar = editor.getModule('toolbar');
| toolbar.addHandler('image', () => {
| self.selectLocalImage();
| });
| },
| methods: {
| selectLocalImage() {
| const input = document.createElement('input');
| input.setAttribute('type', 'file');
| input.click();
| input.onchange = () => {
| const file = input.files[0];
| if (file) {
| // 在这里调用你的图片上传逻辑,并获取图片的URL
| // 假设你上传后得到了图片URL
| const url = '你的图片URL';
| // 插入图片到编辑器
| this.insertToEditor(url);
| }
| };
| },
| insertToEditor(url) {
| const range = this.$refs.quillEditor.quill.getSelection();
| this.$refs.quillEditor.quill.insertEmbed(range.index, 'image', url);
| }
| }
| };
| </script>
| <style lang="scss" scoped>
| .editor {
| line-height: normal !important;
| height: 400px;
| margin-bottom: 50px;
| }
| //.ql-snow .ql-tooltip[data-mode="link"]::before {
| // content: "请输入链接地址:";
| //}
| //.ql-snow .ql-tooltip.ql-editing a.ql-action::after {
| // border-right: 0px;
| // content: "保存";
| // padding-right: 0px;
| //}
|
| </style>
|
|