富文本編輯器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. 通過編輯器的選項(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ì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
vue雙向數(shù)據(jù)綁定原理分析、vue2和vue3原理的不同點(diǎn)
這篇文章主要介紹了vue雙向數(shù)據(jù)綁定原理分析、vue2和vue3原理的不同點(diǎn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
Vue.js學(xué)習(xí)筆記之 helloworld
vue是法語(yǔ)中視圖的意思,Vue.js是一個(gè)輕巧、高性能、可組件化的MVVM庫(kù),同時(shí)擁有非常容易上手的API。有需要的小伙伴可以參考下2016-08-08
Vue+ElementUI怎么處理超大表單實(shí)例講解
在本篇文章里小編給大家整理的是一篇關(guān)于Vue+ElementUI怎么處理超大表單實(shí)例講解內(nèi)容,以后需要的朋友可以跟著學(xué)習(xí)參考下。2021-11-11
vue?async?await?promise等待異步接口執(zhí)行完畢再進(jìn)行下步操作教程
在Vue中可以使用異步函數(shù)和await關(guān)鍵字來控制上一步執(zhí)行完再執(zhí)行下一步,這篇文章主要給大家介紹了關(guān)于vue?async?await?promise等待異步接口執(zhí)行完畢再進(jìn)行下步操作的相關(guān)資料,需要的朋友可以參考下2023-12-12
vue使用this.$message不生效的部分原因及解決方案
這篇文章主要介紹了vue使用this.$message不生效的部分原因及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09
vue v-for直接循環(huán)數(shù)字實(shí)例
今天小編就為大家分享一篇vue v-for直接循環(huán)數(shù)字實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11

