[英]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.