亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

html注入帶參數的調用函數

html注入帶參數的調用函數

搖曳的薔薇 2023-05-11 14:43:12
我有一個問題,如果我想向我的click屬性添加一個參數,那么它會在呈現后立即調用該函數這是我的測試 html:return html`       <button class="menu-btn" @click="${this._OpenSubMenu(1)}>test</button>" `;}和功能:_OpenSubMenu(test:number) {    console.log("Hello")  }Hello頁面呈現后立即輸出。那么如何在向我的函數添加參數的同時避免這種情況呢?
查看完整描述

1 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超7個贊

你需要讓你的函數返回一個函數。然后您的點擊函數將執行返回的函數,并且由于閉包仍然可以訪問參數。


例如..


_OpenSubMenu(test:number) {

  var that = this;

  return function () {

     console.log("Hello");

     //test is also a closure so you can use here

     //that will equal this

  }

}

如果你想訪問this,你也可以使用箭頭功能


_OpenSubMenu(test:number) {

  return () => {

     console.log("Hello");

     //test is also a closure so you can use here

     //this will also still be valid here

  }

}


查看完整回答
反對 回復 2023-05-11
  • 1 回答
  • 0 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號