鍍金池/ 問答/HTML/ react里遇到一個(gè)鏈接跳轉(zhuǎn)問題

react里遇到一個(gè)鏈接跳轉(zhuǎn)問題

//實(shí)現(xiàn)一個(gè)點(diǎn)擊跳轉(zhuǎn)功能

代碼:

  constructor(props){
     super(props);
     this.clickFunc = this.clickFunc.bind(this);  
     //由于ESlint原因,沒法利用bind在jsx里綁定事件
  }


  clickFunc=(url)=>{
      window.location.href = url;
  }

  //render 方法里

  return (
      <div className="linkWrap" onClick={this.clickFunc(url)}>
            //還是環(huán)境問題,這里的點(diǎn)擊跳轉(zhuǎn)鏈接,沒法用a標(biāo)簽....,
            //所以寫了一個(gè)跳轉(zhuǎn)方法
      </div>
  );

問題:這樣一來只要頁面一加載就會(huì)自動(dòng)執(zhí)行一次clickFunc方法,導(dǎo)致看不到原本的頁面,有沒有什么辦法,在實(shí)例化的時(shí)候不會(huì)執(zhí)行方法,并且可以綁定方法?

回答
編輯回答
何蘇葉
onClick={() => this.clickFunc(url)}
2017年10月31日 10:59
編輯回答
笑浮塵
onClick={this.clickFunc.bind(this,url)}
2018年4月7日 08:35