react 中使用switch-case 隨記


在生命周期中使用switch-case

switch(num){
     case "1":return 'a'; 
     case "2":return 'b'; 
     case "3":return 'c'; 
     default:return 'd';
}

在render中使用switch-case(注意括號)

render: inputMethod => (
  <div>
    {( ()=>{
      switch(inputMethod){
      case "1": return '日期框';
      case "2": return '初始、結束日期框';
      case "3": return '文本框';
      default:return '數據為空';
    }
   }
  )()}
  </div>
)

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM