<button onclick = { this.btn( data ) }>Btn</button>// 這樣為什么會直接運行這個函數(shù)btn = ( data ) => { console.log( data ) }// 這樣就會正常執(zhí)行btn = ( data ) => () => { console.log( data ) }// 然而 當(dāng)不傳參數(shù)的時候<button onclick = { this.btn }>Btn</button>// 這樣就是正常的btn = ( ) => { console.log( 111 ) }* 如果大佬們有時間的話可以幫我看一下這個么,https://mp.weixin.qq.com/s/rB...我是看了這個才知道這個綁定方法的,說我原來的綁定方法是錯誤的,但是我有點不明白這個綁定的函數(shù)為什么要這樣寫,我是個菜鳥,還希望有空的大佬能告訴我詳細(xì)一點想問一下大佬:1: btn = ( data ) => () => { console.log( data ) } 這個是個什么函數(shù)?2: 可不可以幫我解釋一下上邊的 demo !
1 回答

慕姐4208626
TA貢獻(xiàn)1852條經(jīng)驗 獲得超7個贊
一句話重點:事件綁定的 是函數(shù),不是函數(shù)的執(zhí)行。
// 事件綁定函數(shù),正確btn = () => { console.log( 111 ) } <button onclick = { this.btn }>Btn</button>// 事件綁定函數(shù)的執(zhí)行,錯誤btn = () => { console.log( 111 ) } <button onclick = { this.btn( data ) }>Btn</button>// btn函數(shù)執(zhí)行也返回函數(shù),事件綁定函數(shù),正確btn = ( data ) => () => { console.log( data ) } <button onclick = { this.btn( data ) }>Btn</button>
添加回答
舉報
0/150
提交
取消