admin管理员组文章数量:1336643
I'm trying to debounce a function from running for 500ms. Following the documentation here:
.html#debounce-Param-Attribute-for-v-model-removed
methods: {
// Get the data needed for this page
fetchData: _.debounce(function () {
this.$http.get('widgets/quickfindordernumber/' + this.quickFindOrderNumber).then(function (response) {
console.log(response.body)
}, function (error) {
console.log(error);
});
}, 500)
}
But when running this function I get an error in the console Uncaught ReferenceError: _ is not defined
I have tried removing the _. in front of debounce but it says debounce is not defined either.
I'm trying to debounce a function from running for 500ms. Following the documentation here:
https://v2.vuejs/v2/guide/migration.html#debounce-Param-Attribute-for-v-model-removed
methods: {
// Get the data needed for this page
fetchData: _.debounce(function () {
this.$http.get('widgets/quickfindordernumber/' + this.quickFindOrderNumber).then(function (response) {
console.log(response.body)
}, function (error) {
console.log(error);
});
}, 500)
}
But when running this function I get an error in the console Uncaught ReferenceError: _ is not defined
I have tried removing the _. in front of debounce but it says debounce is not defined either.
- 2 _ is underscore or lodash, an external library, not Vue. – Bert Commented Mar 15, 2017 at 15:56
1 Answer
Reset to default 6In the example, VueJS use the debounce
function from external library like underscoreJS or lodash.
To works with it, you just include this in your file (after install this in your npm modules) like this :
import _ from 'lodash';
new Vue({
// ...
methods: {
// Get the data needed for this page
fetchData: _.debounce(function () {
this.$http.get('widgets/quickfindordernumber/' + this.quickFindOrderNumber).then(function (response) {
console.log(response.body)
}, function (error) {
console.log(error);
});
}, 500)
}
});
本文标签: javascriptVueJS 2 Uncaught ReferenceErroris not defined with debounceStack Overflow
版权声明:本文标题:javascript - VueJS 2 Uncaught ReferenceError: _ is not defined with debounce - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742416787a2470870.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论