gpt4 book ai didi

javascript - "TypeError: Cannot read property ' innerBlocks ' of null"for InnerBlocks in Gutenberg

转载 作者:行者123 更新时间:2023-11-30 19:33:48 24 4
gpt4 key购买 nike

我最近问了一个关于相同的问题 topic .在那里我自己发现了问题。但不幸的是,我得到了一个新的错误:

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>
);
}
});

然后我检查了作为插件嵌入的内置 script.js 文件。我们遇到以下情况,this.props.blocknull

key: "componentDidMount",
value: function componentDidMount() {
var innerBlocks = this.props.block.innerBlocks; // only synchronize innerBlocks with template if innerBlocks are empty or a locking all exists

if (innerBlocks.length === 0 || this.getTemplateLock() === 'all') {
this.synchronizeBlocksWithTemplate();
}

if (this.state.templateInProcess) {
this.setState({
templateInProcess: false
});
}
}

更新

变量this.props有以下变量:

Variables of this.props

有没有人面临同样的问题或有解决方法?

最佳答案

再次,我解决了我自己的问题。最后,这个问题对我来说并不清楚,但它确实有效。

我现在所做的就是简单地使用 wp.editor 作为 InnerBlocks 组件的导入实例。有了它,它现在加载了完整的 InnerBlocks 编辑器,我现在可以在其中添加自定义 block 。

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";

关于javascript - "TypeError: Cannot read property ' innerBlocks ' of null"for InnerBlocks in Gutenberg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56167315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com