繁体   English   中英

Editor.js 生命周期钩子

[英]Editor.js lifecycle hooks

如何为块实现生命周期挂钩?

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 实例删除之前调用

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

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) {}
}

暂无
暂无

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

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