富文本編輯器vue2-editor實現(xiàn)全屏功能
vue2-editor非常不錯,可惜并未帶全屏功能,自己實現(xiàn)了一個,供大家參考。
實現(xiàn)思路:自定義模塊。
1. 定義全屏模塊Fullscreen
/** * 編輯器的全屏實現(xiàn) */ 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. 最后在全局樣式中加入全屏的樣式,我這個樣式中控制了編輯器的高度,默認是自適應(yīng)高度的。
.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; }
總結(jié)
以上所述是小編給大家介紹的富文本編輯器vue2-editor實現(xiàn)全屏功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
vue-cli中的babel配置文件.babelrc實例詳解
Babel是一個廣泛使用的轉(zhuǎn)碼器,可以將ES6代碼轉(zhuǎn)為ES5代碼,從而在現(xiàn)有環(huán)境執(zhí)行。本文介紹vue-cli腳手架工具根目錄的babelrc配置文件,感興趣的朋友一起看看吧2018-02-02Vue?elementui如何實現(xiàn)表格selection的默認勾選
這篇文章主要介紹了Vue?elementui如何實現(xiàn)表格selection的默認勾選問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06vue props傳值失敗 輸出undefined的解決方法
今天小編就為大家分享一篇vue props傳值失敗 輸出undefined的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09antd vue 如何調(diào)整checkbox默認樣式
這篇文章主要介紹了antd vue 如何調(diào)整checkbox默認樣式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12