本文介绍了“无法读取未定义的属性 'getEditedPostAttribute'"用于古腾堡的 InnerBlocks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 WordPress 中的古腾堡编辑器实现一个块组件.在那里我想使用 InnerBlocks

I'm trying to implement a block component for the Gutenberg Editor in WordPress. There I want to use the InnerBlocks component which is also used for example for the columns component provided by Wordpress itself.

在控制台中我收到消息:

When I try to start using the component, I always get the same error in the frontend:

我根据这个文档实现了类似的此处:

In the console I get the message:

TypeError: Cannot read property 'getEditedPostAttribute' of undefined
    at script.build.js?ver=1:27811
    at getNextMergeProps (script.build.js?ver=1:103469)
    at new ComponentWithSelect (script.build.js?ver=1:103487)
    at zf (react-dom.min.js?ver=16.6.3:69)
    at Mf (react-dom.min.js?ver=16.6.3:87)
    at ph (react-dom.min.js?ver=16.6.3:98)
    at eg (react-dom.min.js?ver=16.6.3:125)
    at fg (react-dom.min.js?ver=16.6.3:126)
    at wc (react-dom.min.js?ver=16.6.3:138)
    at fa (react-dom.min.js?ver=16.6.3:137)

)},保存(道具){const {attributes, className} = props;返回 (<div style={blockStyle}><InnerBlocks.Content/>

I have implemented it similar according to this documentation here:

);}});

const {registerBlockType} = wp.blocks;const {InspectorControls, RichText, MediaUpload} = wp.editor;import {TextControl} from '@wordpress/components';import {InnerBlocks} from '@wordpress/block-editor';let blockStyle = { marginTop: "25px", marginBottom: "25px;"};registerBlockType('myself/test-component', { title: 'Test component', icon: 'editor-insertmore', category: 'common', attributes: { title: { type: 'string' } }, edit(props) { const {setAttributes, attributes} = props; function setTitle(changes) { setAttributes({ title: changes }) } return ( <div style={blockStyle}> <TextControl placeholder="Titel" value={attributes.title} onChange={setTitle} /> <InnerBlocks templateLock={false} renderAppender={( () => <InnerBlocks.ButtonBlockAppender/> )} /> </div> ) }, save(props) { const {attributes, className} = props; return ( <div style={blockStyle}> <InnerBlocks.Content/> </div> ); }});

我现在的问题是,有没有其他人遇到过这个问题,或者我怎样才能让这个组件工作?

My question is now, is there someone else who has this problem or how can I make this component work?

推荐答案

所以我自己发现了错误.我再次检查了源 script.build.js 并找到以下几行

So I have found the error myself. I have checked again the source script.build.js and found the following lines

var _select2 = select('core/editor'),
      getEditedPostAttribute = _select2.getEditedPostAttribute;

我只使用了@wordpress/block-editor 包.所以我现在将以下包添加到 script.js 文件并再次运行它.

I have only used the @wordpress/block-editor package. So I now added the following package to the script.js file and ran it again.

npm install @wordpress/editor

在 script.js 中

In the script.js

import {InnerBlocks} from "@wordpress/editor";

错误现在消失了,但不幸的是我得到了一个新错误.

The error disappeared now but I got a new one unfortunately.

这篇关于“无法读取未定义的属性 'getEditedPostAttribute'"用于古腾堡的 InnerBlocks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:23