小编Con*_*sen的帖子

如何修复 WordPress 中的“错误加载块:无效参数:属性”错误

我正在尝试扩展在 Tasty Recipes 插件中注册的现有块。我在侧边栏添加了一个控件来处理给定饮食类型的选择,但是当选择一个选项时,会显示以下错误:

加载块时出错:无效参数:属性

目前在 WordPress 5.2.1 上运行,我正在尝试扩展Tasty Recipes 插件

扩展TastyRecipes.js

/**
 * Add custom attribute to store diet type
 */

var addCustomAttributes = function( settings, name ) {

    if ( name !== 'wp-tasty/tasty-recipe' ) {
        return settings;
    }

    settings.attributes = Object.assign( settings.attributes, {
        dietType: {
            type: 'string',
            // ? Setting default here causes break
        },
    } );

    return settings;
}

wp.hooks.addFilter( 'blocks.registerBlockType', 'wp-tasty/tasty-recipe', addCustomAttributes );


/**
 * Create HOC to add diet type control to inspector controls …
Run Code Online (Sandbox Code Playgroud)

wordpress wordpress-gutenberg gutenberg-blocks

5
推荐指数
0
解决办法
3166
查看次数