简体   繁体   English

如何在Quill JS中添加图像?

[英]How to add image in Quill JS?

I can't figure out how to get images to work like in the example on http://quilljs.com/ . 我无法弄清楚如何让图像像http://quilljs.com/上的示例一样工作。

I tried adding <span title="Image" class="ql-format-button ql-image"></span> to the toolbar, which adds the button, but clicking on the button does nothing and I can't find anything in the documentation. 我尝试将<span title="Image" class="ql-format-button ql-image"></span>到工具栏,添加按钮,但点击按钮什么也没做,我找不到任何东西在文档中。 Any suggestion? 有什么建议吗?

Updated Answer 更新的答案

As of version 1.0 and beyond you no longer need to add the tool-tip module it's included by default. 从版本1.0及更高版本开始,您不再需要添加默认包含的工具提示模块。 An example of how to enable it would be this. 如何启用它的一个例子就是这个。

    <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>

Edit: This is no longer accurate as of 1.0. 编辑:从1.0开始不再准确。 Chris Hawkes's answer is correct. 克里斯霍克斯的回答是正确的。

This unfortunately doesn't seem documented anywhere but you need to include the image-tooltip module. 遗憾的是,这似乎没有在任何地方记录,但您需要包含image-tooltip模块。 For example, this is what the editor on the quilljs.com homepage uses: 例如,这是quilljs.com主页上的编辑器使用的内容:

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

well the above answer is the correct in the js, but you have to add html to the editor, example: 以上答案在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>

so after that put in the js 所以在那之后放入js

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

As of Quill version 1.3, none of the answers above work anymore. 从Quill 1.3版开始,上述答案都不再适用。 Unfortunately, the official documentation hasn't progressed much either. 不幸的是,官方文档也没有取得多大进展。

You have two ways to solve your problem, both work for official themes Snow and Bubble . 你有两种方法来解决你的问题,这两种方法都适用于官方主题SnowBubble Either way, you do not have to add the following code: 无论哪种方式,您都不必添加以下代码:

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

Way 1 : Initialize quill as following: 方式1 :初始化羽毛笔如下:

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

Way 2 : Initialize quill as following: 方式2 :初始化羽毛笔如下:

<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,
        ...
    },
    ...
});

As of version 1.3, Quill does not support resizing images. 从版本1.3开始,Quill不支持调整图像大小。 One can do it with a custom module, though. 不过,可以使用自定义模块来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM