You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
598 B

2 years ago
  1. /* type 1 2 3
  2. 1 对应 h1
  3. 2 对应 h2
  4. 3 对应 h3 */
  5. /*
  6. 复杂的多分支的逻辑收敛为一个函数通过一个专门的函数来写分支逻辑模板中只负责调用即可 */
  7. const getTitle = (type) => {
  8. if(type === 1) {
  9. return <h1>h1标题</h1>
  10. }
  11. if(type === 2) {
  12. return <h2>h2标题</h2>
  13. }
  14. if(type === 3) {
  15. return <h3>h3标题</h3>
  16. }
  17. }
  18. function App() {
  19. return (
  20. <div className="App">
  21. {getTitle(1)}
  22. {getTitle(2)}
  23. {getTitle(3)}
  24. </div>
  25. );
  26. }
  27. export default App;