Javascript &引用;TypeError:无法读取属性';内部块';“无效”的定义;用于古腾堡的内部块
我最近也问了一个同样的问题。在那里,我自己发现了这个问题。但不幸的是,我又犯了一个新错误:Javascript &引用;TypeError:无法读取属性';内部块';“无效”的定义;用于古腾堡的内部块,javascript,wordpress,reactjs,wordpress-gutenberg,Javascript,Wordpress,Reactjs,Wordpress Gutenberg,我最近也问了一个同样的问题。在那里,我自己发现了这个问题。但不幸的是,我又犯了一个新错误: TypeError: Cannot read property 'innerBlocks' of null at InnerBlocks.synchronizeBlocksWithTemplate (script.build.js?ver=1:149405) at InnerBlocks.componentDidMount (script.build.js?ver=1:149366)
TypeError: Cannot read property 'innerBlocks' of null
at InnerBlocks.synchronizeBlocksWithTemplate (script.build.js?ver=1:149405)
at InnerBlocks.componentDidMount (script.build.js?ver=1:149366)
at zc (react-dom.min.js?ver=16.6.3:146)
at wc (react-dom.min.js?ver=16.6.3:138)
at fa (react-dom.min.js?ver=16.6.3:137)
at ng (react-dom.min.js?ver=16.6.3:149)
at Se (react-dom.min.js?ver=16.6.3:40)
因此,我用相同的代码尝试了它,但没有成功:
const {registerBlockType} = wp.blocks;
const {InspectorControls, RichText, MediaUpload} = wp.editor;
import {TextControl} from '@wordpress/components';
import {InnerBlocks} from '@wordpress/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>
);
}
});
更新
变量this.props
具有以下变量:
是否有人面临同样的问题或有解决方法?再一次,我解决了自己的问题。问题最终对我来说并不清楚,但它起了作用 我现在所做的只是简单地使用
wp.editor
作为InnerBlocks
组件的导入实例。有了它,它现在加载了完整的InnerBlocks编辑器,我现在可以在其中添加自定义块
const {registerBlockType} = wp.blocks;
const {InspectorControls, RichText, InnerBlocks} = wp.editor; //Imported the InnerBlocks from this source.
import {CheckboxControl, TextControl} from '@wordpress/components';
// Removed this line
// import {InnerBlocks} from "@wordpress/editor";
我看不出您在哪里传递“block”属性。@rrd我已尝试将该属性设置为InnerBlocks组件,但没有成功。在构建过程之后,它看起来像一个内部
道具。我已经用一个屏幕截图更新了我的问题,显示了this.props
对象。那么this.props.block看起来是空的,所以innerBlocks永远不会出现。这就是为什么会出现错误——事实上,错误本身也会告诉你同样的情况。@rrd,没错,我已经注意到了。但是为什么这个块是空的
。除了本网站上描述的这些属性外,我没有定义该对象的选项:
const {registerBlockType} = wp.blocks;
const {InspectorControls, RichText, InnerBlocks} = wp.editor; //Imported the InnerBlocks from this source.
import {CheckboxControl, TextControl} from '@wordpress/components';
// Removed this line
// import {InnerBlocks} from "@wordpress/editor";