您好,登錄后才能下訂單哦!
vue2-editor非常不錯,可惜并未帶全屏功能,自己實現了一個,供大家參考。
實現思路:自定義模塊。
1. 定義全屏模塊Fullscreen
/** * 編輯器的全屏實現 */ import noScroll from 'no-scroll' export default class Fullscreen { constructor (quill, options = {}) { this.quill = quill this.options = options this.fullscreen = false this.editorContainer = this.quill.container.parentNode.parentNode } handle () { if (! this.fullscreen) { this.fullscreen = true this.editorContainer.className = 'ql-editor ql-blank editor-fullscreen' noScroll.on() }else{ this.fullscreen = false this.editorContainer.className = 'ql-editor ql-blank' noScroll.off() } } }
Fullscreen.js
2. 通過編輯器的選項注冊模塊,我是放在了全局的Global.vue中,其他頁面直接引用這個選項
const EDITOR_OPTIONS = { modules: { fullscreen: {}, toolbar: { container: [ [{ header: [false, 1, 2, 3, 4, 5, 6] }], ["bold", "italic", "underline", "strike"], // toggled buttons [ { align: "" }, { align: "center" }, { align: "right" }, { align: "justify" } ], ["blockquote", "code-block"], [{ list: "ordered" }, { list: "bullet" }, { list: "check" }], [{ indent: "-1" }, { indent: "+1" }], // outdent/indent [{ color: [] }, { background: [] }], // dropdown with defaults from theme ["link", "image", "video"], ["clean"], // remove formatting button ['fullscreen'] ], handlers: { fullscreen() { this.quill.getModule('fullscreen').handle() } } } } }
3. 在頁面中引用
<vue-editor useCustomImageHandler @imageAdded="handleImageAdded" v-model="entity.content" :editorOptions="$global.EDITOR_OPTIONS" class="editor"> </vue-editor>
import {VueEditor, Quill} from "vue2-editor" import Fullscreen from '../Fullscreen' Quill.register('modules/fullscreen', Fullscreen)
4. 最后在全局樣式中加入全屏的樣式,我這個樣式中控制了編輯器的高度,默認是自適應高度的。
.editor .ql-editor{ height: 300px; } .editor-fullscreen{ background: white; margin: 0 !important; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 100000; .ql-editor{ height: 100%; } .fullscreen-editor { border-radius: 0; border: none; } .ql-container { height: calc(100vh - 3rem - 24px) !important; margin: 0 auto; overflow-y: auto; } } .ql-fullscreen{ background:url('./assets/images/fullscreen.svg') no-repeat center!important; }
總結
以上所述是小編給大家介紹的富文本編輯器vue2-editor實現全屏功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。