javascript Editor.js生命周期挂钩

ih99xse1  于 2023-01-24  发布在  Java
关注(0)|答案(1)|浏览(100)

如何实现块的生命周期钩子?
https://editorjs.io/tools-api#lifecycle-hooks
我有这个:

let config = { 
    /** 
     * Id of Element that should contain the Editor 
     */ 
    holder : 'alinea-5', 
    
    /** 
     * Available Tools list. 
     * Pass Tool's class or Settings object for each Tool you want to use 
     */ 
    tools: {
        header  : Header,
        list        : List
    }
};

const elEditorData = document.querySelector('.js-editor-data');

if (elEditorData.value) {
    config.data         = {};
    config.data.blocks  = JSON.parse(elEditorData.value);
}

new EditorJS(config);

正如你所看到的,有一些editor.js的东西在那里。
我需要清理我的html当删除一个块。现在我必须做一些与生命周期挂钩"删除",但如何?当删除块通过工具栏我想清理整个html块:

document.querySelector('.alinea-5').remove();

这是否干扰了文档中关于删除事件的说明?
removed:在从页中移除Block内容后但在删除Block示例前调用

2exbekwf

2exbekwf1#

块生命周期钩可在块内使用:

class MyBlockTool {
   /**
   * Called after Block content is added to the page
   */
  rendered() {}

  /**
   * Called each time Block content is updated
   */
  updated() {}

  /**
   * Called after Block content is removed from the page but before Block instance deleted
   */
  removed() {}

  /**
   * Called after Block is moved by move tunes or through the API
   * 
   * @param {MoveEvent} event 
   */
  moved(event) {}
}

相关问题