首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RichText组件出错

RichText组件出错
EN

WordPress Development用户
提问于 2023-03-09 18:29:22
回答 1查看 81关注 0票数 1

WP版本6.1.1

据我所知,我没有做什么特别的事。当我将我的自定义块添加到一个页面时,我输入它,在第二个字符上,我在浏览器控制台中得到一个带有block-editor.min.js:26:522080D1

我的edit.js:

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

export default function Edit() {
    return (
        
    );
}
  1. 对这个具体问题有什么见解吗?
  2. 有没有任何方法来设置我的站点/块来使用block-editor.js的非小型化版本,这样以后调试这样的事情就更容易了吗?
EN

回答 1

WordPress Development用户

回答已采纳

发布于 2023-03-09 18:49:56

你忽略了重要的必备道具:

值: String 必需。使HTML字符串可编辑。如果提供的话,HTML应该是有效的,并且在tagName内部是有效的。onChange (值:字符串):函数必需的。当值更改时调用。

这些道具不是可选的,您遇到的错误很可能是因为它试图调用onChange函数,但没有提供。

核心开发人员网站的整体手册中的正式文件有一些例子:

https://developer.wordpress.org/block-editor/reference-guides/richtext/#example

代码语言:javascript
复制
    edit( { attributes, setAttributes } ) {
        const blockProps = useBlockProps();

        return (
             setAttributes( { content } ) } // Store updated content as a block attribute
                placeholder={ __( 'Heading...' ) } // Display this text before any content has been added by the user
            />
        );
    },

    save( { attributes } ) {
        const blockProps = useBlockProps.save();

        return ; // Saves Content added in the editor... to the database for frontend display
    }
} );

但重要的是,不包括这些价值观是毫无意义的。不像具有内部状态和值的标准HTML输入,必须告诉它的值是什么,当您进行更改时,需要使用onChange在其他地方更新该值。这就是为什么示例调用setAttribute,它不是可选的。

票数 3
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

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

复制
相关文章

相似问题

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