2 回答

TA貢獻1906條經驗 獲得超3個贊
<h5 className="recipes__title"> //An html header
//Containing...
{
item.recipe.label < 20 ? // If the item.recipe.label is less than 20 then...
`${item.recipe.label}` // the label
: `${item.recipe.label.substring(0, 25)} //else the first 25 characters of the label followed by
...` // the string "..."
}
</h5>
您可以在此處找到有關三元運算符(有條件地解析為兩個表達式之一的表達式)的信息
您可以在此處找到有關模板文字(可以包含要解析的 javascript 的字符串)的信息

TA貢獻1827條經驗 獲得超8個贊
JSX 部分:
<element> { // You can put your Javascript here but mostly inline script. } </element
`${...}`
這是 ES6 中引入的字符串模板。它用于構建字符串。${}
表示要處理JS,變量名或函數調用。
子串(0, 25)
這是檢查標簽是否最多 25 個字符的部分。如果不是,它會選擇前 25 個字符,然后在其后添加省略號(...
)。
添加回答
舉報