使用时ServerSideRender
wordpress gutenberg组件,我看到以下通知。
wp.components.ServerSideRender is deprecated. Please use wp.serverSideRender instead.
这是我的测试代码:
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { Fragment } = wp.element;
const { InspectorControls } = wp.blockEditor;
const {
PanelBody, SelectControl, ServerSideRender, TextControl, ToggleControl,
} = wp.components;
registerBlockType( \'test-me/test-to-block\', {
title: __( \'Test Me\' ),
icon: \'shield\',
category: \'common\',
keywords: [
__( \'Test Me\' ),
__( \'Test\' ),
__( \'msbd\' ),
],
attributes: {
adAlignment: {
type: \'string\',
default: \'center-align\',
},
isWrapper: {
type: \'boolean\',
default: true,
},
},
edit: ( props ) => {
const { setAttributes, attributes } = props;
const { adAlignment, isWrapper } = attributes;
return (
<Fragment>
<div className={ `test-me ${ className }` }>
<ServerSideRender
block="test-me/test-to-block"
attributes={ attributes }
/>
</div>
</Fragment>
);
},
save: ( props ) => {
const { attributes, className = \'\' } = props;
return (
<div className={ `test-me ${ className }` }>
<ServerSideRender
block="test-me/test-to-block"
attributes={ attributes }
/>
</div>
);
},
} );
如何修改此脚本以使用新脚本
wp.serverSideRender
组成部分
SO网友:WebElaine
这只意味着他们移动了组件。更换此部件:
const {
PanelBody, SelectControl, ServerSideRender, TextControl, ToggleControl,
} = wp.components;
使用
const { serverSideRender } = wp;
const {
PanelBody, SelectControl, TextControl, ToggleControl,
} = wp.components;
除非他们更改了有关组件的任何其他内容,否则导入组件的位置应该是唯一需要的更新。
Be careful with the first letter of \'serverSideRender\', lower case!!