【问题标题】:Quill 1.3.6, Upload all images when paste them to the editorQuill 1.3.6,将所有图像粘贴到编辑器时上传
【发布时间】:2018-08-04 10:45:16
【问题描述】:

粘贴富文本(HTML)时我需要上传所有图片,然后用从上传 API 获取的 url 替换它们的 url。 所以我厌倦了这个:

const Delta = Quill.import('delta');
this.quill.clipboard.addMatcher('img', async (node, delta) => {
  console.log(node, delta);
  const url = await new Promise(resolve => {
    // upload image
    this.props.uploadImageURL({ url: delta.ops[0].insert.image }).then(res => {
      if (res.success) {
        resolve(res.data.path)
      } else {
        resolve('')
      }
    }, () => { resolve('') })
  });

  if (url) {
    return {
      ops: [{
        insert: {
          image: url
        }
      }]
    };
  } else {
    return new Delta();
  }
});

然后错误:

谁能帮帮我?

【问题讨论】:

    标签: frontend richtextbox rich-text-editor quill


    【解决方案1】:

    此时您似乎无法使用异步匹配器功能。

    下面是没有异步的简化工作示例。一旦你尝试返回一个 Promise(异步),这将失败:

    const Delta = Quill.import('delta');
    quill.clipboard.addMatcher('img', (node, delta) => {
      console.log(node, delta);
      const url = 'http://www.placehold.it/666x333.jpg';
    
      return new Delta().insert({image: url});
    
    });
    

    看来,你需要找到一种同步的方式来替换图片。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-07
      • 2018-01-27
      • 2017-11-12
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多