Узел: Uncaught TypeError: moduleClass не является конструктором - PullRequest
0 голосов
/ 21 декабря 2018

Я хочу импортировать обработчик в quill.Но я все еще получаю эту ошибку Uncaught TypeError: moduleClass is not a constructor

Вот как работает функция с quill

import Quill from 'quill';

// IMAGE HANDLER
    const imageHandler = () => {
      const input = document.createElement('input');

      input.setAttribute('type', 'file');
      input.setAttribute('accept', 'image/*');
      input.click();

      input.onchange = async () => {
        const file = input.files[0];
        const formData = new FormData();

        formData.append('image', file);

        // Save current cursor state
        const range = this.quill.getSelection(true);

        // Insert temporary loading placeholder image
        this.quill.insertEmbed(range.index, 'image', `${ window.location.origin }/images/loaders/placeholder.gif`);

        // Move cursor to right side of image (easier to continue typing)
        this.quill.setSelection(range.index + 1);

        const res = await apiPostNewsImage(formData); // API post, returns image location as string e.g. 'http://www.example.com/images/foo.png'

        // Remove placeholder image
        this.quill.deleteText(range.index, 1);

        // Insert uploaded image
        this.quill.insertEmbed(range.index, 'image', res.body.image);
      }
    }

// Initialize quill
    var quill = new Quill('#editor', {
      theme: 'snow',
      modules: {
        toolbar: '#toolbar',
        handlers: {
          image: imageHandler,
        }
      }
    });

Когда я открываю, где есть ошибка, это дает мне эту часть кода из quill.js

{
    key: 'addModule',
    value: function addModule(name) {
      var moduleClass = this.quill.constructor.import('modules/' + name);
      this.modules[name] = new moduleClass(this.quill, this.options.modules[name] || {});
      return this.modules[name];
    }

Я не уверен, что сделал что-то неправильно или если есть проблема со стороны иглы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...