Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use anti-shake function in vue

Shulou Source: shulou.com Published: 2022-05-31 13:25:09 09月18日 Update

This article mainly introduces the relevant knowledge of how to use the anti-shake function in vue, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will have something to gain after reading this vue article on how to use the anti-shake function, let's take a look.

The specific methods are as follows:

1. First, create a new utils.js file and define an anti-shake function in the file

Export default {

Debounce (fn, delay = 300) {

Var timer

Return function () {

Var args = arguments

If (timer) {

ClearTimeout (timer)

}

Timer = setTimeout () = > {

Fn.apply (this, args)

}, delay)

}

}

}

two。 After the anti-shake function is defined, create a vue.js project in vue-cli

Vue create project-name

After the 3.vue.js project is created, use the import method to introduce the utils.js file in the project

Import utils from "@ / js/utils"

4. Finally, after introducing the utils.js file, you can use the methods method to call the anti-shake function.

Export default {

Methods: {

Search: utils.debounce (function () {

Let v = this

Let serchURL = `/ movie/search?q=$ {v.searchText} & start=0&count= 10`

V.$axios

.get (serchURL)

.then (response = > {

V.processSearchData (response.data)

})

.catch (error = > {

Console.log (error)

})

.finally ()

})

}

}

This is the end of the article on "how to use anti-shake function in vue". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use anti-shake function in vue". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Function document method knowledge project content article value easy to operate article easy to understand more watch industry information channel channel Zhongchuang build learn Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Apple Huawei Docker Shulou Tech Info