【问题标题】:EditorJs warning "«blocks.stretchBlock()» is deprecated and will be removed in the next major release. Please use the «BlockAPI» instead."EditorJs 警告“«blocks.stretchBlock()» 已弃用,将在下一个主要版本中删除。请改用 «BlockAPI»。”
【发布时间】:2021-07-16 07:36:10
【问题描述】:

我正在使用 EditorJs,但它在控制台中给了我这个警告

«blocks.stretchBlock()» is deprecated and will be removed in the next major release. Please use the «BlockAPI» instead.

如何在 EditorJs 中使用«BlockAPI»

这是我的 EditorJs 初始化:

const editor = new EditorJS({
  tools: {
    header: Header,
    list: List,
    image: Image,
    embed: {
      class: Embed,
      config: {
        services: {
          youtube: true
        }
      }
    },
  },
})

【问题讨论】:

    标签: javascript editorjs


    【解决方案1】:

    Block API 通过 block 属性中的构造函数属性传递。您必须从那里获取它并将其设置为您的块的属性。

    它应该看起来像这样:

    class CustomBlock {
      private data;
      private block;
    
      constructor({
        data,
        block
      }) {
        this.data = data;
        this.block = block;
      }
    
      toggleStretched() {
        this.block.stretched = !!this.data.stretched;
      }
    
      // Rest of the block implementation
    }
    

    官方文档好像不是最新的,但是我发现 this file 有 Block API 的描述。

    【讨论】:

      猜你喜欢
      • 2018-08-21
      • 2018-08-18
      • 2021-05-09
      • 1970-01-01
      • 2017-05-25
      • 1970-01-01
      • 2012-08-07
      • 2021-05-17
      • 1970-01-01
      相关资源
      最近更新 更多