| | |
| | | <template> |
| | | <div> |
| | | 测试自定义组件展示ddddd |
| | | <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" |
| | | } |
| | | </script> |
| | | name:'test', |
| | | data() { |
| | | return { |
| | | content: '', |
| | | editorOptions: { |
| | | // Quill编辑器的选项 |
| | | placeholder: '请输入内容!', |
| | | modules:{ |
| | | toolbar:{ |
| | | container:toolbarOptions |
| | | } |
| | | } |
| | | |
| | | <style scoped> |
| | | } |
| | | }; |
| | | }, |
| | | 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> |