搜尋
問答 在 debounce 函數中存取 this.$router
在 debounce 函數中存取 this.$router
P粉541796322 2023-09-06 16:21:17 查看 857

0

我想根據使用者輸入的內容更改 URL。 防手震功能運作正常。但我似乎無法存取“this”變數。

“this”隱式有型別“any”,因為它沒有型別註解

searchbarPokemon: debounce(function (e: any) {
  this.$router.push(e.target.value);  
  console.log(e)
}, 1000)

而且去抖動發回的資料是最後一個字母。可以得到完整的句子嗎?

編輯:在e.target.value處找到完整值

Your Answer
提交

1 個答案
0

您可以建立一個箭頭函數來保留this'上下文:

searchbarPokemon: debounce((e: any) => {
  this.$router.push(e.target.value);  
  console.log(e)
}, 1000)
2023-09-07 15:38:08

提交

Hot Tools

vc9-vc14(32+64位元)運行庫合集(連結在下方)

vc9-vc14(32+64位元)運行庫合集(連結在下方)

phpStudy安裝所需運行函式庫集合下載

VC9 32位

VC9 32位

VC9 32位元 phpstudy整合安裝環境運行庫

php程式設計師工具箱完整版

php程式設計師工具箱完整版

程式設計師工具箱 v1.0 php整合環境

VC11 32位

VC11 32位

VC11 32位元 phpstudy整合安裝環境運行庫

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用