首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在控制台中生成的导致阻塞验证失败的错误

在控制台中生成的导致阻塞验证失败的错误
EN

WordPress Development用户
提问于 2023-03-14 15:59:33
回答 1查看 40关注 0票数 2

在我的自定义块插件中,我使用创建块来生成块环境以进行块编辑。在我的‘`src/ed.js文件中,我有以下设置.

代码语言:javascript
运行
复制
import { __ } from '@wordpress/i18n';
import {
    useBlockProps,
    Fragment,
    RichText,
    BlockControls,
} from '@wordpress/block-editor';
import './editor.scss';

export default function Edit( { attributes, setAttributes } ) {
    const { text } = attributes;

    // additional options for our RichText component - https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md
    return (
        <Fragment>
            <BlockControls controls={[{
                title: "Button 1",
                icon: "admin-generic",
                onClick : () => console.log("Button 1 clicked!"),
            },]} />
            <RichText
                { ...useBlockProps() }
                onChange={ ( value ) => setAttributes( { text: value } ) }
                value={ text }
                placeholder={ __( 'My chocolate placeholder', 'chocolate' ) }
                tagName="h4"
                allowedFormats={ 'core/bold' }
            />
        </Fragment>
    );
}

...But当我运行npm,并转到我的编辑页面时,我在控制台中得到以下错误.

代码语言:javascript
运行
复制
Block validation: Block validation failed for `course-blocks/chocolate` ( ....}

我的save.js文件看起来如此..。

代码语言:javascript
运行
复制
import { useBlockProps, RichText } from '@wordpress/block-editor';

export default function save( { attributes } ) {
    const { text } = attributes;
    return (
        <RichText.Content
            { ...useBlockProps.save() }
            tagName="h4"
            value={ text }
        />
    );
}

我的属性正被从我的block.json.

代码语言:javascript
运行
复制
{
    "$schema": "https://schemas.wp.org/trunk/block.json",
    "apiVersion": 2,
    "name": "course-blocks/chocolate",
    "version": "0.1.0",
    "title": "Chocolate",
    "category": "text",
    "description": "A playground for block development.",
    "supports": {
        "html": false
    },
    "textdomain": "chocolate",
    "editorScript": "file:./index.js",
    "editorStyle": "file:./index.css",
    "style": "file:./style-index.css",
    "attributes": {
        "text": {
            "type": "string",
            "source": "html",
            "selector": "h4"
        }
    }
}
EN

回答 1

WordPress Development用户

发布于 2023-03-14 16:47:01

Fragment导出位于@wordpress/element包中,而不是block-editor中。

尽管如此,您不再需要显式地编写<Fragment> (截至反应16.2)。相反,您只需使用“空标签”:

代码语言:javascript
运行
复制
return (
    <>
        <p>One</p>
        <p>Two</p>
    </>
);
票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/414633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档