我正在尝试为 WordPress 中的古腾堡编辑器实现一个块组件。在那里我想使用该InnerBlocks
组件,该组件也用于例如 Wordpress 本身提供的列组件。
当我尝试开始使用该组件时,我总是在前端遇到相同的错误:
在控制台中,我收到消息:
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 {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>
);
}
});
我现在的问题是,是否还有其他人遇到此问题,或者我如何使该组件正常工作?