经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » JavaScript » 查看文章
富文本编辑器vue2-editor实现全屏功能
来源:cnblogs  作者:消失的风  时间:2019/5/27 8:50:20  对本文有异议

vue2-editor非常不错,可惜并未带全屏功能,自己实现了一个,供大家参考。

实现思路:自定义模块。

1. 定义全屏模块Fullscreen

  1. /**
  2. * 编辑器的全屏实现
  3. */
  4. import noScroll from 'no-scroll'
  5. export default class Fullscreen {
  6. constructor (quill, options = {}) {
  7. this.quill = quill
  8. this.options = options
  9. this.fullscreen = false
  10. this.editorContainer = this.quill.container.parentNode.parentNode
  11. }
  12. handle () {
  13. if (! this.fullscreen) {
  14. this.fullscreen = true
  15. this.editorContainer.className = 'ql-editor ql-blank editor-fullscreen'
  16. noScroll.on()
  17. }else{
  18. this.fullscreen = false
  19. this.editorContainer.className = 'ql-editor ql-blank'
  20. noScroll.off()
  21. }
  22. }
  23. }
Fullscreen.js

2. 通过编辑器的选项注册模块,我是放在了全局的Global.vue中,其他页面直接引用这个选项

  1. const EDITOR_OPTIONS = {
  2. modules: {
  3. fullscreen: {},
  4. toolbar: {
  5. container: [
  6. [{ header: [false, 1, 2, 3, 4, 5, 6] }],
  7. ["bold", "italic", "underline", "strike"], // toggled buttons
  8. [
  9. { align: "" },
  10. { align: "center" },
  11. { align: "right" },
  12. { align: "justify" }
  13. ],
  14. ["blockquote", "code-block"],
  15. [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
  16. [{ indent: "-1" }, { indent: "+1" }], // outdent/indent
  17. [{ color: [] }, { background: [] }], // dropdown with defaults from theme
  18. ["link", "image", "video"],
  19. ["clean"], // remove formatting button
  20. ['fullscreen']
  21. ],
  22. handlers: {
  23. fullscreen() {
  24. this.quill.getModule('fullscreen').handle()
  25. }
  26. }
  27. }
  28. }
  29. }
Global.vue

3. 在页面中引用

  1. <vue-editor
  2. useCustomImageHandler
  3. @imageAdded="handleImageAdded"
  4. v-model="entity.content"
  5. :editorOptions="$global.EDITOR_OPTIONS"
  6. class="editor">
  7. </vue-editor>
  1. import {VueEditor, Quill} from "vue2-editor"
  2. import Fullscreen from '../Fullscreen'
  3. Quill.register('modules/fullscreen', Fullscreen)

4. 最后在全局样式中加入全屏的样式,我这个样式中控制了编辑器的高度,默认是自适应高度的。

  1. .editor .ql-editor{
  2. height: 300px;
  3. }
  4. .editor-fullscreen{
  5. background: white;
  6. margin: 0 !important;
  7. position: fixed;
  8. top: 0;
  9. left: 0;
  10. width: 100%;
  11. height: 100%;
  12. z-index: 100000;
  13. .ql-editor{
  14. height: 100%;
  15. }
  16. .fullscreen-editor {
  17. border-radius: 0;
  18. border: none;
  19. }
  20. .ql-container {
  21. height: calc(100vh - 3rem - 24px) !important;
  22. margin: 0 auto;
  23. overflow-y: auto;
  24. }
  25. }
  26. .ql-fullscreen{
  27. background:url('./assets/images/fullscreen.svg') no-repeat center!important;
  28. }
App.vue

 

原文链接:http://www.cnblogs.com/disappearwind/p/10925204.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号