最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I alter image size in a Quill Editor- React? - Stack Overflow

programmeradmin5浏览0评论

I want to give the user flexibility to change image size in a quill editor, How can I do it? I am currently doing it right this but I am getting error. Here is my code:

Quill.register("modules/imageResize", ImageResize);

Editor.modules = {
  toolbar: [
    [{ header: "1" }, { header: "2" }, { font: [] }],
    [{ size: [] }],
    ["bold", "italic", "underline", "strike", "blockquote", "code-block"],
    [
      { list: "ordered" },
      { list: "bullet" },
      { indent: "-1" },
      { indent: "+1" }
    ],
    ["link", "image", "video"],
    ["clean"]
  ],
  imageResize: {
    displaySize: true
  }
};

My error is:

TypeError: Cannot read property 'register' of undefined Function.register C:/Users/muddinahmed/Documents/My Learning/Projects/React/blog-app/node_modules/quill/dist/quill.js:1122 1119 | this.imports[path] = target; 1120 | if ((path.startsWith('blots/') || path.startsWith('formats/')) && target.blotName !== 'abstract') { 1121 | _parchment2.default.register(target); > 1122 | } else if (path.startsWith('modules') && typeof target.register === 'function') { | ^ 1123 | target.register(); 1124 | } 1125 | }

How to do it?

I want to give the user flexibility to change image size in a quill editor, How can I do it? I am currently doing it right this but I am getting error. Here is my code:

Quill.register("modules/imageResize", ImageResize);

Editor.modules = {
  toolbar: [
    [{ header: "1" }, { header: "2" }, { font: [] }],
    [{ size: [] }],
    ["bold", "italic", "underline", "strike", "blockquote", "code-block"],
    [
      { list: "ordered" },
      { list: "bullet" },
      { indent: "-1" },
      { indent: "+1" }
    ],
    ["link", "image", "video"],
    ["clean"]
  ],
  imageResize: {
    displaySize: true
  }
};

My error is:

TypeError: Cannot read property 'register' of undefined Function.register C:/Users/muddinahmed/Documents/My Learning/Projects/React/blog-app/node_modules/quill/dist/quill.js:1122 1119 | this.imports[path] = target; 1120 | if ((path.startsWith('blots/') || path.startsWith('formats/')) && target.blotName !== 'abstract') { 1121 | _parchment2.default.register(target); > 1122 | } else if (path.startsWith('modules') && typeof target.register === 'function') { | ^ 1123 | target.register(); 1124 | } 1125 | }

How to do it?

Share Improve this question edited Feb 11, 2020 at 14:03 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Feb 11, 2020 at 5:56 LoGanLoGan 1151 gold badge5 silver badges14 bronze badges 2
  • What is the error that you are getting? – Agney Commented Feb 11, 2020 at 6:02
  • TypeError: Cannot read property 'register' of undefined Function.register C:/Users/muddinahmed/Documents/My Learning/Projects/React/blog-app/node_modules/quill/dist/quill.js:1122 1119 | this.imports[path] = target; 1120 | if ((path.startsWith('blots/') || path.startsWith('formats/')) && target.blotName !== 'abstract') { 1121 | _parchment2.default.register(target); > 1122 | } else if (path.startsWith('modules') && typeof target.register === 'function') { | ^ 1123 | target.register(); 1124 | } 1125 | } – LoGan Commented Feb 11, 2020 at 6:06
Add a ment  | 

2 Answers 2

Reset to default 11
import ImageResize from 'quill-image-resize-module-react';

Quill.register('modules/imageResize', ImageResize);

modules = {
  imageResize: {
     parchment: Quill.import('parchment'),
     modules: ['Resize', 'DisplaySize']
  }
}

For react.js

import ReactQuill, { Quill } from 'react-quill';
import imageResize from 'quill-image-resize-module-react';
import "quill/dist/quill.snow.css";
.
.
.
Quill.register('modules/imageResize', imageResize);
.
.
.
  const modules = {
   .
   .
   .
    imageResize: {
      modules: ["Resize", "DisplaySize"],
    },
  };

package.json

    "quill": "^2.0.2",
    "react-quill": "^2.0.0",
    "quill-image-resize-module-react": "^3.0.0",
发布评论

评论列表(0)

  1. 暂无评论