【问题标题】:How to add image in Quill JS?如何在 Quill JS 中添加图像?
【发布时间】:2015-05-14 13:24:29
【问题描述】:

我不知道如何让图像像 http://quilljs.com/ 的示例中那样工作。

我尝试将<span title="Image" class="ql-format-button ql-image"></span> 添加到工具栏,该工具栏添加了按钮,但单击该按钮没有任何作用,并且我在文档中找不到任何内容。有什么建议吗?

【问题讨论】:

  • 你好。我来这里只是为了向看到此问题的任何人添加更多信息。我相信以下链接对任何使用(或开始使用)Quill 的人都有很大帮助:github.com/loagit/Quill-Examples-and-FAQ

标签: javascript richtext rte quill


【解决方案1】:

更新答案

从 1.0 版及更高版本开始,您不再需要添加默认包含的工具提示模块。如何启用它的一个例子就是这样。

    <script>
            var toolbarOptions = [
                ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
                ['blockquote', 'code-block'],

                [{ 'header': 1 }, { 'header': 2 }],               // custom button values
                [{ 'list': 'ordered'}, { 'list': 'bullet' }],
                [{ 'script': 'sub'}, { 'script': 'super' }],      // superscript/subscript
                [{ 'indent': '-1'}, { 'indent': '+1' }],          // outdent/indent
                [{ 'direction': 'rtl' }],                         // text direction

                [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
                [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
                [ 'link', 'image', 'video', 'formula' ],          // add's image support
                [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme
                [{ 'font': [] }],
                [{ 'align': [] }],

                ['clean']                                         // remove formatting button
            ];

        var quill = new Quill('#editor', {
            modules: {
                toolbar: toolbarOptions
            },

            theme: 'snow'
        });
    </script>

【讨论】:

  • 可以上传大图吗?并将其存储在服务器上并保存图像路径而不是 base64 数据
  • 这篇文章非常有帮助。我刚刚添加了该数组并设置了如图所示的选项,它为我提供了一个完整设置的坏蛋编辑器,这让我现在认为 JIRA/Confluence 正在使用 Quill。
  • @hardik 这有一些将图像存储在服务器上而不是使用 base64 数据的解决方案:github.com/quilljs/quill/issues/1089
【解决方案2】:

编辑:从 1.0 开始,这不再准确。 Chris Hawkes 的 answer 是正确的。

不幸的是,这似乎没有在任何地方记录,但您需要包含 image-tooltip 模块。例如,这是 quilljs.com 主页上的编辑器使用的:

quill = new Quill('#editor', {
  modules: {
    'toolbar': { container: '#toolbar' },
    'image-tooltip': true,
    'link-tooltip': true
  },
  theme: 'snow'
});

【讨论】:

    【解决方案3】:

    从 Quill 1.3 版开始,以上答案都不再适用。 不幸的是,官方文档也没有太大进展。

    您有两种解决问题的方法,它们都适用于官方主题 Snow 和 Bubble。 无论哪种方式,您不必添加以下代码:

    'image-tooltip': true,
    'link-tooltip': true
    

    方式 1: 初始化 quill 如下:

    var editor = new Quill('#editorDiv', 
    {
        modules: {
          toolbar: [
                ...
                ['image'],
                ...
            ],
            //not needed anymore: 'image-tooltip': true,
            //not needed anymore: 'link-tooltip': true
            ...
        },
        ...
    });
    

    方式 2: 初始化 quill 如下:

    <div id="editorToolbarDiv">
      ...
      <button class="ql-image"></button>
    </div>
    <div id="editorDiv"></div>
    
    var editor = new Quill('#editorDiv', 
    {
        modules: {
            toolbar: '#editorToolbarDiv',
            //not needed anymore: 'image-tooltip': true,
            //not needed anymore: 'link-tooltip': true,
            ...
        },
        ...
    });
    

    从 1.3 版开始,Quill 不支持调整图像大小。不过,我们可以使用自定义模块来做到这一点。

    【讨论】:

    【解决方案4】:

    上面的答案在js中是正确的,但是你必须在编辑器中添加html,例如:

    <span class="ql-format-group">
      <span title="Link" class="ql-format-button ql-link"></span>
      <span class="ql-format-separator"></span>
      <span title="Image" class="ql-format-button ql-image"></span>
    </span>
    

    然后放入js

    quill = new Quill('#editor', {
      modules: {
        'toolbar': { container: '#toolbar' },
        'image-tooltip': true,
        'link-tooltip': true
      },
      theme: 'snow'
    });
    

    【讨论】:

    • 为什么没有一个关于如何创建工具栏的示例实际创建示例上方显示的工具栏?或者例如“标题”是什么,为什么这些示例甚至不包含?
    • 我对他们糟糕的示例和文档感到非常沮丧。很遗憾,这个工具正是我所需要的——但是,哇。真的吗?我的意思是没有人喜欢文档,但我的天哪,这太棒了
    • 那是什么,你看不懂?
    猜你喜欢
    • 1970-01-01
    • 2018-04-08
    • 2015-07-29
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2020-05-26
    • 2022-07-04
    • 2017-09-29
    相关资源
    最近更新 更多