WP版本6.1.1
据我所知,我没有做什么特别的事。当我将我的自定义块添加到一个页面时,我输入它,在第二个字符上,我在浏览器控制台中得到一个带有block-editor.min.js:26:522080的D1。
我的edit.js:
import { __ } from '@wordpress/i18n';
import { useBlockProps, RichText } from '@wordpress/block-editor';
import './editor.scss';
export default function Edit() {
return (
);
}block-editor.js的非小型化版本,这样以后调试这样的事情就更容易了吗?发布于 2023-03-09 18:49:56
你忽略了重要的必备道具:
值: String 必需。使HTML字符串可编辑。如果提供的话,HTML应该是有效的,并且在tagName内部是有效的。
onChange(值:字符串):函数必需的。当值更改时调用。
这些道具不是可选的,您遇到的错误很可能是因为它试图调用onChange函数,但没有提供。
核心开发人员网站的整体手册中的正式文件有一些例子:
https://developer.wordpress.org/block-editor/reference-guides/richtext/#example
edit( { attributes, setAttributes } ) {
const blockProps = useBlockProps();
return (
setAttributes( { content } ) } // Store updated content as a block attribute
placeholder={ __( 'Heading...' ) } // Display this text before any content has been added by the user
/>
);
},
save( { attributes } ) {
const blockProps = useBlockProps.save();
return ; // Saves Content added in the editor... to the database for frontend display
}
} );但重要的是,不包括这些价值观是毫无意义的。不像具有内部状态和值的标准HTML输入,必须告诉它的值是什么,当您进行更改时,需要使用onChange在其他地方更新该值。这就是为什么示例调用setAttribute,它不是可选的。
https://wordpress.stackexchange.com/questions/414507
复制相似问题