InsteadoffightingagainstJavaScriptfunctions, itempowersyouwith a syntaxwhereyoucanclearlycreateanif-elsestatementor a for-eachloopwhenworkingwith a list.
Topassdatafrom a parenttochild, youcanusepropsbyaddingtheexportkeywordto a variable.
要從父代向子代傳遞數據,可以通過在變量中添加導出關鍵字來使用道具。
Andnowyoucanpassdataintothiscomponent.
現在你可以向這個組件傳遞數據了。
Andifyouhave a tonofprops, youcanusethespreadsyntaxtokeepyourcodelookingfitandhealthy.
如果你有大量的道具,你可以使用擴展文法,讓你的代碼看起來更健康。
Nowformorecomplexcomponenttrees, youhave a contextAPIjustlikeReact.
現在,對於更復雜的組件樹,你可以像 React 一樣使用上下文 API。
Andifthatwasn't enough, Sveltealsohas a reallynicemechanismcalledstores, whicharelikeobservablesthatcanbesharedanywhereinthe a dollarsigninfrontofthem.