Block主题模板部件-为什么保存一个部件会更新其他部件?
创始人
2024-12-22 21:30:16
0

这个问题可能是由于未注意到在局部渲染上下文中使用了相同的属性名称所致。在局部渲染上下文中,块中属性的名称不能与父级或兄弟级块的属性名称相同。

一种解决方法是在保存部分时指定一个唯一的名称,以确保它不会与其他部分产生冲突。示例代码如下:

/**
* 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: '

相关内容

热门资讯

开挂透视!hhpoker是正品... 开挂透视!hhpoker是正品吗,微乐河南家乡麻将辅助脚本,技法教程(有挂攻略)-哔哩哔哩1、玩家可...
专业透视!哈糖大菠萝可以开挂吗... 专业透视!哈糖大菠萝可以开挂吗,微信微乐辅助器下载,积累教程(有挂总结)-哔哩哔哩1、哈糖大菠萝可以...
详情透视!wejoker辅助器... 详情透视!wejoker辅助器要钱玩吗,微信小程序微乐辅助器,机巧教程(真的有挂)-哔哩哔哩暗藏猫腻...
详细透视!wepoker有透视... 您好,wepoker有透视底牌吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527505...
科普透视!aapoker怎么选... 科普透视!aapoker怎么选牌,微乐斗地主有挂吗,指南书教程(有挂存在)-哔哩哔哩1、进入游戏-大...
专业透视!pokerrrr2辅... 专业透视!pokerrrr2辅助,微信卡五星小程序辅助,诀窍教程(了解有挂)-哔哩哔哩1.poker...
关于透视!德普之星透视免费,微... 关于透视!德普之星透视免费,微乐游戏小程序脚本,妙招教程(有挂解惑)-哔哩哔哩1、进入到德普之星透视...
了解透视!德普之星透视辅助,微... 了解透视!德普之星透视辅助,微乐自建房辅助工具在哪,课程教程(有挂规律)-哔哩哔哩1、完成德普之星透...
揭露透视!德普之星透视辅助软件... 揭露透视!德普之星透视辅助软件激活码,微乐小程序辅助工具2025,攻略教程(竟然有挂)-哔哩哔哩一、...
分享透视!hhpoker智能辅... 分享透视!hhpoker智能辅助插件,手机微信小程序游戏破解器下载,绝活儿教程(果真有挂)-哔哩哔哩...