富文本上传图片到自定义服务器也不容易

183 阅读1分钟

quill

感觉用起来还是有点麻烦 用ImageUploader插件的人比较多,用法

import ImageUploader from "quill-image-uploader";
import "quill-image-uploader/dist/quill.imageUploader.min.css";
import Image from 'quill/formats/image';

const modules = {

  name: 'imageUploader',
  module: ImageUploader,
  options: {
    upload: (file) => {
      debugger;
      return new Promise((resolve, reject) => {
        const formData = new FormData();
        formData.append('file', file);
        let query = {
          directory: 'article'
        }
        // Replace with your image upload URL
        handleFileUpload(formData, query).then(res => {
          debugger;
          resolve(res.msg); // Ensure this returns the correct image URL

        })

        // fetch('YOUR_IMAGE_UPLOAD_URL', {
        //   method: 'POST',
        //   body: formData,
        // })
        //   .then((response) => response.json())
        //   .then((result) => {
        //     resolve(result.imageUrl); // Ensure this returns the correct image URL
        //   })
        //   .catch((error) => {
        //     reject('上传失败');
        //   });
      });
    },
  }

};

但是就算这样了也还不行,报了2个错: vue-quill报错:

Uncaught Error: [Parchment] Unable to create imageBlot blot

quill-image-uploader插件也报错

TypeError: Cannot read properties of null (reading 'ops')

imageBlot这个错误我搜了下别人的解决方案,结果看到这个: github.com/slab/quill/…

第1个高赞答案我已经做了,再看下这位仁兄的解决方案,要改一大串!我的妈,只是传个图片,还要加这么多代码吗?

瞬间,quill我都不想用了。