3

我正在尝试使用 create-guten-block 编写 Gutenberg-Block。当我运行它时,我在控制台中收到一些警告,表明我正在使用的一些元素已被弃用:

deprecated.min.js?ver=2.6.1:1 wp.editor.RichText.Content is deprecated. Please use wp.blockEditor.RichText.Content instead.

因此,我对我的代码进行了一些更改。在我的“blocks.js”中,我将声明从

const {RichText} = wp.editor;

至:

const {RichText} = wp.blockEditor;

在“init.php”中,我在之前导入“wp-editor”的地方导入了“wp-block-editor”。RichText 在这里作为示例;对于 wp.blockEditor 中的其他元素,例如 ColorPalette 和 InspectorControls,我收到了相同的警告。

当我测试它时,在包含这些更改后,该块就像以前一样工作,但我仍然收到相同的警告消息。它让我发疯,因为我的 RichText 元素有问题,而且我不知道它是否与此有关,所以我想排除这种可能性。

我一般是初学者,我之前没有使用过 react(也没有使用过 wordpress/gutenberg),所以我还没有完全理解我在这里做什么。我假设我在某处犯了一个愚蠢的错误,但我不知道为什么这不起作用。任何帮助表示赞赏!

4

1 回答 1

0

我不太确定,但我认为依赖项仍然是 wp-editor。您正在解构 wp.blockEditor 对象(请参阅:https ://wesbos.com/destructuring-objects/ )。您也可以使用 wp.blockEditor.RichText 来访问该组件。

于 2020-02-14T12:07:14.620 回答