• vue中使用vue-quill-editor及上传图片到自己服务器


    第一步,下载依赖

    cnpm install vue-quill-editor --save

    第二步,再main.js里引入组件(我这里是全局注册)

    // 富文本编辑器
    import VueQuillEditor from 'vue-quill-editor'
    import 'quill/dist/quill.core.css'
    import 'quill/dist/quill.snow.css'
    import 'quill/dist/quill.bubble.css'
      
    Vue.use(VueQuillEditor)

    第三步,如果要上传图片到自己服务器的话如下

    cnpm install vue-quill-editor-upload --save

    接下来再组件中使用

    //js布冯
    import {quillRedefine} from 'vue-quill-editor-upload'
    data(){
      return{
          editorOption: {
                modules:{
                    toolbar:[
                        ['image'],
                        [{ 'color': [] }, { 'background': [] }]
                    ]
                }
            },  
        }  
    },
    components: {quillRedefine},
      computed: {
          editor() {
            return this.$refs.myQuillEditor.quill;
        }
      },
    methods: {
          onEditorReady(editor) { // 准备编辑器
            },
        onEditorBlur(){}, // 失去焦点事件
        onEditorFocus(){}, // 获得焦点事件
        onEditorChange(event){
            console.log(event.html)
            this.htmls = event.html
        }, // 内容改变事件
     },
    created: function() {      
        let that = this;
        that.upLoadUrl=upLoadUrl+'/?width=300';
        that.editorOption = quillRedefine(
            {
              // 图片上传的设置
              uploadConfig: {
                action: that.upLoadUrl,  // 必填参数 图片上传地址
                // 必选参数  res是一个函数,函数接收的response为上传成功时服务器返回的数据
                // 你必须把返回的数据中所包含的图片地址 return 回去
                res: (respnse) => {
                    console.log(respnse)
                    var path = respnse.path//这里return你的图片地址即可
                  return path
                },
                name: 'img'  // 图片上传参数名
              },
              toolOptions: [
                  [{'color': []}, {'background': []}],
                  [ 'image']
              ]
            }
          )
      }

    temple里的代码是

    <quill-editor 
                                    v-model="dataInfo.description" 
                                    ref="myQuillEditor" 
                                    :options="editorOption" 
                                    @blur="onEditorBlur($event)" 
                                    @focus="onEditorFocus($event)"
                                    @change="onEditorChange($event)">
                                </quill-editor>

    这样就可以正常操作了,注:上方的 upLoadUrl 需要根据你们的上传地址修改

  • 相关阅读:
    用goto做异常处理
    零长度数组的妙用
    DTMF三种模式(SIPINFO,RFC2833,INBAND)
    Myeclipse下的struts2.3.8 配置 保证绝对好用
    Linux内核--内核数据类型
    Linux内核:kthread_create(线程)、SLEEP_MILLI_SEC
    3.4.4 数据预留和对齐(skb_reserve, skb_push, skb_put, skb_pull)
    Linux 2.6内核中新的锁机制--RCU
    Linux中SysRq的使用(魔术键)
    CentOS Linux服务器安全设置
  • 原文地址:https://www.cnblogs.com/ldlx-mars/p/10767447.html
Copyright © 2020-2023  润新知