第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

為什么我的自定義古騰堡塊在保存時(shí)會(huì)損壞?

為什么我的自定義古騰堡塊在保存時(shí)會(huì)損壞?

翻閱古今 2023-11-02 21:54:41
這是我第一次創(chuàng)建自定義古騰堡塊。我已經(jīng)能夠成功生成幾個(gè)塊。但是,當(dāng)我創(chuàng)建帖子并使用該塊時(shí),它可以工作,但是當(dāng)我退出并返回帖子時(shí),我收到此錯(cuò)誤:該塊包含意外或無效內(nèi)容我做了一些研究,發(fā)現(xiàn)如果編輯和保存的內(nèi)容不一致,可能會(huì)導(dǎo)致這種情況。我一直無法找到不一致的地方,但我可以使用一些幫助。下面是注冊(cè)塊的代碼,該塊確實(shí)按預(yù)期執(zhí)行,但在第一次創(chuàng)建塊后不允許我進(jìn)行編輯。感謝幫助!const { registerBlockType } = wp.blocks;const {     RichText,     InspectorControls,     ColorPalette,    MediaUpload,    RawHTML} = wp.editor;const { PanelBody, IconButton } = wp.components;registerBlockType('myblog/call-to-action', {    title: 'Call To Action',    description: 'Block to generate a call to action',    icon: 'align-full-width',    category: 'widgets',    //Custom Attributes    attributes: {        title: {            type: 'string',            source: 'html',            selector: 'h2'        },        titleColor: {            type: 'string',            default: 'white'        },        backgroundColor: {            type: 'string',            default: 'blue'        },        body: {            type: 'string',            source: 'html',            selector: 'p'        }    },   //Built-in Functions    edit({attributes, setAttributes}) {        const{            title,            priceCard,            titleColor,            backgroundColor,        } = attributes;        //Custom Functions                function onChangeTitle(newTitle) {            setAttributes( { title: newTitle } );        }        function onChangePriceCard(newCard) {            setAttributes( { priceCard: newCard } );        }        function onTitleColorChange(newColor){            setAttributes( { titleColor: newColor } );        }        function onChangeBackgroundColor(newBackground) {            setAttributes( { backgroundColor: newBackground })        }
查看完整描述

1 回答

?
繁花如伊

TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個(gè)贊

priceCard您的屬性中缺少該屬性,例如:


registerBlockType('myblog/call-to-action', {

    ...

    //Custom Attributes

    attributes: {

        ...

        priceCard: { // is missing

            ... // set type, default etc..

        }

    },

    ...

}

在更新的塊中添加/刪除了該屬性,然后重新加載保存的帖子時(shí),該屬性丟失,從而導(dǎo)致問題。


此外,在進(jìn)行簡(jiǎn)單的屬性更新時(shí),可以刪除代碼中的自定義函數(shù)部分,以便setAttributes()直接使用,例如:


<RichText

    key="editable"

    tagName="p"

    placeholder="Paste Shortcode"

    value={priceCard}

    onChange={(value) => setAttributes({ priceCard: value })} // attribute: value

/>

這將使您的代碼更易于管理/故障排除。


查看完整回答
反對(duì) 回復(fù) 2023-11-02
  • 1 回答
  • 0 關(guān)注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)