这个问题可能是由于未注意到在局部渲染上下文中使用了相同的属性名称所致。在局部渲染上下文中,块中属性的名称不能与父级或兄弟级块的属性名称相同。
一种解决方法是在保存部分时指定一个唯一的名称,以确保它不会与其他部分产生冲突。示例代码如下:
/**
* Save a part of a block.
*/
function savePart( props ) {
const { attributes, setAttributes } = props;
const { title, content } = attributes;
// Here, you can choose a unique name for your part.
const partName = 'my-part';
return (
{title}
{content}
)
}
/**
* Render a block with the saved part.
*/
function renderBlock( props, partName ) {
const { attributes } = props;
// Check if the part was saved.
const isPartSaved = attributes[partName];
// Here, you can render the block with the saved part.
return (
{attributes.title}
{isPartSaved && (
)}
);
}
/**
* Save the whole block.
*/
function saveBlock( props ) {
const { attributes } = props;
return (
{attributes.title}
{attributes.content}
{/* Save the first part */}
{/* Save the second part */}
);
}
registerBlockType( 'my-plugin/my-block', {
title: 'My Block',
category: '