富文本編輯器vue2-editor實(shí)現(xiàn)全屏功能
vue2-editor非常不錯(cuò),可惜并未帶全屏功能,自己實(shí)現(xiàn)了一個(gè),供大家參考。
實(shí)現(xiàn)思路:自定義模塊。
1. 定義全屏模塊Fullscreen
/**
* 編輯器的全屏實(shí)現(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. 通過(guò)編輯器的選項(xiàng)注冊(cè)模塊,我是放在了全局的Global.vue中,其他頁(yè)面直接引用這個(gè)選項(xiàng)
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. 在頁(yè)面中引用
<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. 最后在全局樣式中加入全屏的樣式,我這個(gè)樣式中控制了編輯器的高度,默認(rèn)是自適應(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實(shí)現(xiàn)全屏功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Vue2老項(xiàng)目配置ESLint和Prettier完整步驟
ESLint是一個(gè)靜態(tài)代碼分析工具,用于檢查JavaScript代碼的語(yǔ)法結(jié)構(gòu)和查找程序錯(cuò)誤,Prettier是一個(gè)代碼格式化工具,這篇文章主要給大家介紹了關(guān)于Vue2老項(xiàng)目配置ESLint和Prettier的完整步驟,需要的朋友可以參考下2024-08-08
vue-cli中的babel配置文件.babelrc實(shí)例詳解
Babel是一個(gè)廣泛使用的轉(zhuǎn)碼器,可以將ES6代碼轉(zhuǎn)為ES5代碼,從而在現(xiàn)有環(huán)境執(zhí)行。本文介紹vue-cli腳手架工具根目錄的babelrc配置文件,感興趣的朋友一起看看吧2018-02-02
Vue?elementui如何實(shí)現(xiàn)表格selection的默認(rèn)勾選
這篇文章主要介紹了Vue?elementui如何實(shí)現(xiàn)表格selection的默認(rèn)勾選問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-06-06
vue點(diǎn)擊按鈕實(shí)現(xiàn)讓頁(yè)面的某一個(gè)元素全屏展示
這篇文章主要介紹了vue點(diǎn)擊按鈕實(shí)現(xiàn)讓頁(yè)面的某一個(gè)元素全屏展示,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
vue如何通過(guò)params和query傳值(刷新不丟失)
這篇文章主要介紹了vue如何通過(guò)params和query傳值(刷新不丟失),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
vue props傳值失敗 輸出undefined的解決方法
今天小編就為大家分享一篇vue props傳值失敗 輸出undefined的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09
關(guān)于Vue中過(guò)濾器的必懂小知識(shí)
vue過(guò)濾器可以在不改變?cè)紨?shù)據(jù),只是對(duì)數(shù)據(jù)進(jìn)行加工處理后返回過(guò)濾后的數(shù)據(jù)再進(jìn)行調(diào)用處理,下面這篇文章主要給大家介紹了關(guān)于Vue中過(guò)濾器必懂小知識(shí)的相關(guān)資料,需要的朋友可以參考下2021-10-10
antd vue 如何調(diào)整checkbox默認(rèn)樣式
這篇文章主要介紹了antd vue 如何調(diào)整checkbox默認(rèn)樣式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12

