Wordpress 古腾堡区块

Wordpress 古腾堡区块,wordpress,wordpress-gutenberg,gutenberg-blocks,Wordpress,Wordpress Gutenberg,Gutenberg Blocks,我有一个自定义块的问题,它在我重新加载版本页面时向我发送一个错误 我不明白问题出在哪里。就误差而言,实际和预期是相同的 此处显示错误: const { registerBlockType } = wp.blocks; const { __ } = wp.i18n; const { PanelBody, TextControl } = wp.components; const { BlockControls, InspectorControls, RichText } = wp.editor; c

我有一个自定义块的问题,它在我重新加载版本页面时向我发送一个错误

我不明白问题出在哪里。就误差而言,实际和预期是相同的

此处显示错误:

const { registerBlockType } = wp.blocks;
const { __ } = wp.i18n;
const { PanelBody, TextControl } = wp.components;
const { BlockControls, InspectorControls, RichText } = wp.editor;
const { createElement, Fragment } = wp.element

registerBlockType( 'namespace/nottomiss', {
    title: __( 'Nottomiss' ),
    description: __('My description'),
    icon: 'star-filled',
    category: 'widgets',
    supports: { align: true, alignWide: true },
    attributes: {
        label: {
            type: 'string',
            source: 'html',
            selector: 'p',
        },
    title: {
        type: 'string',
        source: 'html',
        selector: 'p',
    },
},
edit: function( props ) {
    const { label, title } = props.attributes;

    function onChangeLabel( newLabel ) {
        props.setAttributes( { label: newLabel } );
    }

    function onChangeTitle( newTitle ) {
        props.setAttributes( { title: newTitle } );
    }

    return (
        <Fragment>
            <BlockControls>
            </BlockControls>
            <InspectorControls>
                <PanelBody title={ __( 'List' ) }>
                </PanelBody>
            </InspectorControls>
            <RichText
                identifier="label"
                tagName="p"
                placeholder=""
                value={ label }
                onChange={ onChangeLabel }
            />
            <RichText
                identifier="title"
                tagName="p"
                placeholder=""
                value={ title }
                onChange={ onChangeTitle }
            />
        </Fragment>
    );
},
save: function( props ) {
    const { label, title } = props.attributes;

    return (
        <div>
            <RichText.Content
                tagName="p"
                value={ label }
            />
            <RichText.Content
                tagName="p"
                value={ title }
            />
        </div>
    );
},
} );
块验证:
命名空间/nottomiss
({object})的块验证失败

预期:

<div class="wp-block-utopiales-nottomiss"><p>label test</p><p>label test</p></div>
标签测试

实际:

<div class="wp-block-utopiales-nottomiss"><p>label test</p><p>title test</p></div>
标签测试

标题测试

这里是我的代码:

const { registerBlockType } = wp.blocks;
const { __ } = wp.i18n;
const { PanelBody, TextControl } = wp.components;
const { BlockControls, InspectorControls, RichText } = wp.editor;
const { createElement, Fragment } = wp.element

registerBlockType( 'namespace/nottomiss', {
    title: __( 'Nottomiss' ),
    description: __('My description'),
    icon: 'star-filled',
    category: 'widgets',
    supports: { align: true, alignWide: true },
    attributes: {
        label: {
            type: 'string',
            source: 'html',
            selector: 'p',
        },
    title: {
        type: 'string',
        source: 'html',
        selector: 'p',
    },
},
edit: function( props ) {
    const { label, title } = props.attributes;

    function onChangeLabel( newLabel ) {
        props.setAttributes( { label: newLabel } );
    }

    function onChangeTitle( newTitle ) {
        props.setAttributes( { title: newTitle } );
    }

    return (
        <Fragment>
            <BlockControls>
            </BlockControls>
            <InspectorControls>
                <PanelBody title={ __( 'List' ) }>
                </PanelBody>
            </InspectorControls>
            <RichText
                identifier="label"
                tagName="p"
                placeholder=""
                value={ label }
                onChange={ onChangeLabel }
            />
            <RichText
                identifier="title"
                tagName="p"
                placeholder=""
                value={ title }
                onChange={ onChangeTitle }
            />
        </Fragment>
    );
},
save: function( props ) {
    const { label, title } = props.attributes;

    return (
        <div>
            <RichText.Content
                tagName="p"
                value={ label }
            />
            <RichText.Content
                tagName="p"
                value={ title }
            />
        </div>
    );
},
} );
const{registerBlockType}=wp.blocks;
常数{{{}=wp.i18n;
const{PanelBody,TextControl}=wp.components;
const{BlockControls,InspectorControls,RichText}=wp.editor;
const{createElement,Fragment}=wp.element
registerBlockType('namespace/nottomiss'{
标题:u uu('Nottomiss'),
描述:u uu(“我的描述”),
图标:“星满”,
类别:“小部件”,
支持:{align:true,alignWide:true},
属性:{
标签:{
键入:“字符串”,
来源:“html”,
选择器:“p”,
},
标题:{
键入:“字符串”,
来源:“html”,
选择器:“p”,
},
},
编辑:功能(道具){
const{label,title}=props.attributes;
函数onChangeLabel(newLabel){
setAttributes({label:newLabel});
}
函数onChangeTitle(newTitle){
setAttributes({title:newTitle});
}
返回(
);
},
保存:功能(道具){
const{label,title}=props.attributes;
返回(
);
},
} );

提前感谢您的回答,

选择器是编辑器从保存的html中提取数据的方式,而当前您的选择器不是针对内容。您可以将选择器更改为以下内容:

attributes: {
  label: {
    type: 'string',
    source: 'html',
    selector: '.label'
  },
  title: {
    type: 'string',
    source: 'html',
    selector: '.title'
  }
}
您可以将保存功能更改为:

save: function(props) {
  const { label, title } = props.attributes

  return (
    <div>
      <div className="label">
        <RichText.Content
          value={ label }
        />
      </div>
      <div className="title">
        <RichText.Content
          value={ title }
        />
      </div>
    </div>
  )
}
保存:功能(道具){
常量{label,title}=props.attributes
返回(
)
}