zoukankan      html  css  js  c++  java
  • VUE的富文本编辑器

    https://www.cnblogs.com/dmcl/p/7152711.html  使用 UEDITOR

    今天介绍一下  

    vue-quill-editor富文本编辑器

    一、npm 安装 vue-quill-editor 
    二、在main.js中引入

    import  VueQuillEditor from 'vue-quill-editor'
    // require styles 引入样式
    import 'quill/dist/quill.core.css'
    import 'quill/dist/quill.snow.css'
    import 'quill/dist/quill.bubble.css'
    
    Vue.use(VueQuillEditor)

    三、在模块中引用

    <template>
         <quill-editor 
          v-model="content" 
          ref="myQuillEditor" 
          :options="editorOption" 
          @blur="onEditorBlur($event)" @focus="onEditorFocus($event)"
          @change="onEditorChange($event)">
        </quill-editor>
    </template> 
    <script>
        import { quillEditor } from 'vue-quill-editor'
        export default{
            data(){
                return {
                    content:null,
                    editorOption:{}
                }
            },
            methods:{
                onEditorBlur(){//失去焦点事件
                },
                onEditorFocus(){//获得焦点事件
                },
                onEditorChange(){//内容改变事件
                }
            }
        }
    </script>   
    那么你如果不需要那么多的工具栏功能要怎么办呢;应该是通过options来修改但是他的默认值是什么的 
    源码:
    import { quillEditor } from 'vue-quill-editor';
    import * as Quill from 'quill'  //引入编辑器
    var fonts = ['SimSun', 'SimHei','Microsoft-YaHei','KaiTi','FangSong','Arial'];
    var Font = Quill.import('formats/font');
    Font.whitelist = fonts; //将字体加入到白名单
    Quill.register(Font, true);
    const toolbarOptions = [
    ['bold', 'italic', 'underline', 'strike'],
    ['blockquote'],

    [{ 'header': 1 }, { 'header': 2 }],
    [{ 'list': 'ordered'}, { 'list': 'bullet' }],
    [{ 'script': 'sub'}, { 'script': 'super' }],
    [{ 'indent': '-1'}, { 'indent': '+1' }],
    [{ 'direction': 'rtl' }],

    [{ 'size': ['small', false, 'large', 'huge'] }],
    [{ 'header': [1, 2, 3, 4, 5, 6, false] }],

    [{ 'color': [] }, { 'background': [] }],
    [{ 'font': fonts }], //把上面定义的字体数组放进来

    [{ 'align': [] }],

    ['clean'],
    ['image']
    ]

    export default {
    data () {
    return {
      
    editorOption: {
    placeholder: '在此处输入内容',
    theme: 'snow', // or 'bubble'
    modules:{
    toolbar:{
    container: toolbarOptions,
    handlers: {
    image: function(value) { +图片上传
    if (value) {
    document.querySelector('.avatar-uploader input').click()
    } else {
    this.quill.format('image', false);
    }
    },
    }
    }
    },
    },

    }
    }
    components: {
    quillEditor
    },
    computed: {

    editor() {
    return this.$refs.myTextEditor.quillEditor;
    }
    },
    methods: {
    uploadSuccess (res,file) {
    console.log(res)
    let self = this;
    // res为图片服务器返回的数据
    // 获取富文本组件实例
    let quill = this.$refs.myTextEditor.quill;
    const endFileNmaeList = {
    image: ['png', 'jpg', 'gif', 'jpeg'],
    };
    // 如果上传成功
    if (res.code === 1 && res.data !== null) {
    // 获取光标所在位置
    let length = quill.getSelection().index;
    // res.url为服务器返回的图片地址
    var quillList = quill.getContents();
    if(quillList.ops.length <= 0) {
    quillList = [{
    insert: {image: this.url + res.data}
    }, {
    insert: ' '
    }];
    } else {
    quillList.push({
    insert: {image: this.url + res.data}
    });
    }
    //quill.insertEmbed(length, 'image', this.url + res.data)
    quill.setContents(quillList);
    // 调整光标到最后
    quill.setSelection(length + 1);
    } else {
    this.$message.error( '添加失败');
    }
    // loading动画消失
    this.quillUpdateImg = false;
    },
    }
    }


  • 相关阅读:
    Android-View动画
    Android-RemoteView-桌面小部件
    系统的Drawable(四)-LayerListDrawable
    Android-Drawable(三)
    系统的Drawable(二)-Selector
    系统的Drawable(一)
    Android View事件分发-从源码分析
    打游戏要存进度-备忘录模式
    Java 内部类.md
    docker 常用 命令
  • 原文地址:https://www.cnblogs.com/laixin09/p/9366949.html
Copyright © 2011-2022 走看看