Vue - 如何使用 lodash 去抖动 [英] Vue - How to use lodash debounce
本文介绍了Vue - 如何使用 lodash 去抖动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用在 main.js 中导入的 lodash 的去抖动
I am using debounce from lodash which is imported in main.js
import lodash from 'lodash'
Vue.prototype._ = lodash
我正在使用this._.find(...)
,一切正常.但是如果我使用 debounce 它不起作用.
And I am using like this._.find(...)
, it's all working fine. But if i use debounce it is not working.
<script>
export default {
methods: {
delay: this._.debounce(function () {
// Code
}, 500),
}
}
</script>
它抛出这个错误 Uncaught TypeError: Cannot read property 'debounce' of undefined
使用 this._.debounce(...)
的正确方法是什么?
What could be the right way to use the this._.debounce(...)
?
推荐答案
这应该可行
<script>
import { debounce } from 'lodash-es' // optimized es6-import package, similar to usual 'lodash'
export default {
methods: {
yourCoolFunction: debounce(function (event) { // event is the object parameter given to 'yourCoolFunction' if any
// your tasty code
}, 500),
}
}
这篇关于Vue - 如何使用 lodash 去抖动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文