对save 属性将导致现有块出现问题,因为静态块将标记保存在save 发布内容。如果进行更改,则需要使用deprecated 属性来告诉古腾堡如何处理save 以及帖子内容中的内容。看见here 对于API。
例如:
registerBlockType( \'blockname\', {
//existing properties,
deprecated: [
{
attributes: { // whatever your attributes were for the old version }
save: // the old version of the save function
}
]
})
至于使用
fetch() 函数,您应该能够在返回数据之前按预期在函数中使用它,但我不确定在那里使用它会有什么好处。更好的办法是在
edit 属性并将数据设置为
attribute 街区的。
伪代码:
edit: ( props ) => {
fetch() // not sure what we\'re getting here so...?
.then(data => {
if ( data.thing ) {
this.setAttributes( { attName: data.thing } )
}
})
}
save: function(props) {
return wp.element.createElement(
"div",
{ style: { border: "3px solid " + props.attributes.color } },
{props.attributes.attName}
);
}
})
希望有帮助!