Access this.$router in debounce function
P粉541796322
P粉541796322 2023-09-06 16:21:17
0
1
629

I want to change the URL based on what the user enters. The anti-shake function works fine. But I can't seem to access the "this" variable.

"this" implicitly has type "any" because it has no type annotation

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

And the data sent back by debounce is the last letter. Can I get a complete sentence?

EDIT: Found complete value at e.target.value

P粉541796322
P粉541796322

reply all(1)
P粉968008175

You can create an arrow function to preserve this' context:

searchbarPokemon: debounce((e: any) => {
  this.$router.push(e.target.value);  
  console.log(e)
}, 1000)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!