總結React寫參數的幾種方式


1.在render方法內

 1 class Text extends Component{
 5     render(){
 7         const data=[1,2,3];
 8         return(
 9         {
10           data.map((item,index)=>{

12 return (<div>{item}</div>)
14    }) 
16      } 
19  ) 
22  } 23 }        

2.在構造函數中 當然放在state中也行 

class Text extends Component{
   constructor(){
       super():
       this.data=[1,2,3];
    }
    
     render(){ 
         return(
         {
          this.data.map((item,index)=>{     
                 return (<div>{item}</div>)
           }) 
         } 
        ) 
     }
 }     

2.使用方法

class Text extends Component{
   constructor(){
       super():
       
    }
    data=()=>{
        return [1,2,3];
    }
    
     render(){ 
         return(
         {
          this.data().map((item,index)=>{     
                 return (<div>{item}</div>)
           }) 
         } 
        ) 
     }
 }   

 


免責聲明!

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



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