我正在嘗試創建一個項目列表,其顏色由提供給它的道具決定。顏色數組循環通過,我想根據數組中的顏色更改每個元素的顏色。我目前正在使用內聯樣式,但typescript給我這個錯誤Type 'string' is not assignable to type '{ [key: string]: string; }'.這是我目前編寫的代碼:<div> <div> {this.colors.map(color => { return ( <div id={color} class="colorCircle" style={`background-color: ${color}`}> test </div> ); })} </div></div>
從在 typescript 中作為 prop 提供的數組分配樣式
慕婉清6462132
2022-08-04 17:58:45