0

文字数を取得しようとしていますが、それに基づいてフォントの色を変更したいと考えています。

私は試してみましqueryselector()たが、うまくいきません:

handleChange(event) {
         if( this.charCount > 100){        
              let textcolor = this.template.queryselector("lightning-input-rich-text");
                 textcolor.getformat({color:"red"});
              }
        }
        

私も試しました:

        handleChange(event) {
         if( this.charCount > 100){  
               textcolor = this.template.queryselector('[data-id="summary"]');
           if(textcolor) 
                    this.template.querySelector('[data- 
 id="summarytextcolor"]').className='summarytext';
                 
        }
        }

ここに私のCSSがあります:

.summarytext {color: #ff0000;}

そして、これが私の稲妻コードです。ここでは、変更時に文字数を取得する必要があるリッチテキストフィールドを取得しています。

<lightning-input-rich-text
         data-id="summary"
        label={label.Summary}
        formats={richTextformats}
        label-visible
         valid={richTextValidity}
         message-when-bad-input={richTextErrorMessage}
        class="slds-form-element slds-form-element_stacked summarytext"
        onchange={handleChange}
        value={richTextValue}
        style=" font-weight: normal;">
    </lightning-input-rich-text>

ここに私が得ているエラーがあります:

[NoErrorObjectAvailable] Script error.    a()@https://static.lightning.force.com/cs10/auraFW/javascript/7p9HLMpgnV2GO9MqZhXGUw/aura_prod.js:948:169 {anonymous}()@https://static.lightning.force.com/cs10/auraFW/javascript/7p9HLMpgnV2GO9MqZhXGUw/aura_prod.js:948:362 bt.dispatchEvent()@https://static.lightning.force.com/cs10/auraFW/javascript/7p9HLMpgnV2GO9MqZhXGUw/aura_prod.js:12:12146 bt.dispatchChangeEvent()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/interop/inputRichText.js:2:28144 eval()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/interop/inputRichText.js:2:20578 e.l.emit()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/lightning/quillLib.js:2:142032 e.value()@https://customization-velocity-2311-dev-ed.lightning.force.com/components/lightning/quillLib.js:2:33139

何が問題で、どうすれば修正できますか?

4

1 に答える 1

0

バニラ JavaScript を使用して設定できるはずです。

handleChange(event) {
        this.loading = true;
        if(this.charCount > 100){        
             var warn = richTextValue.fontcolor("Red");
             this.richTextValue = warn;
        }
        this.loading = false;
}

変数「loading」を追加しました。<template if:false={loading}>フォントの色が再レンダリングされるように、入力リッチ テキストが でラップされていることを確認してください。

于 2021-04-12T19:00:13.727 に答える