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()
}
}
}
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. 在页面中引用
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;
}
