我是块编辑器自定义块开发的新手,遇到了一个问题,在任何地方都找不到答案。
当我使用wp的组件时。组件(在我的情况下<Button />
在我的自定义块中,我可以在后端看到它,但它不会在前端渲染。
import \'./style.scss\';
import \'./editor.scss\';
const { __ } = wp.i18n; // Import __() from wp.i18n
const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks
const { Button } = wp.components;
registerBlockType( \'cgb/block-buttonblock\', {
title: __( \'buttonblock - CGB Block\' ), // Block title.
icon: \'shield\', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
category: \'common\', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
keywords: [
__( \'buttonblock — CGB Block\' ),
__( \'CGB Example\' ),
__( \'create-guten-block\' ),
],
edit: function( props ) {
return (
<div className={ props.className }>
<p>— Hello from the backend.</p>
<p>
CGB BLOCK: <code>buttonblock</code> is a new Gutenberg block
</p>
<p>
It was created via{ \' \' }
<code>
<a href="https://github.com/ahmadawais/create-guten-block">
create-guten-block
</a>
</code>.
</p>
<Button isDefault>
Click me on the Backend!
</Button>
</div>
);
},
save: function( props ) {
return (
<div>
<Button>
Click me on the Frontend!
</Button>
<p>— Hello from the frontend.</p>
<p>
CGB BLOCK: <code>buttonblock</code> is a new Gutenberg block.
</p>
<p>
It was created via{ \' \' }
<code>
<a href="https://github.com/ahmadawais/create-guten-block">
create-guten-block
</a>
</code>.
</p>
<p>
Check
</p>
</div>
);
},
} );
我希望它在前端呈现,就像在后端一样。