_.debounce 应用
来源:互联网 发布:淘宝客引流方法 编辑:程序博客网 时间:2024/06/05 10:28
1,定义。
如果用手指一直按住一个弹簧,它将不会弹起直到你松手为止。
也就是说当调用动作n毫秒后,才会执行该动作,若在这n毫秒内又调用此动作则将重新计算执行时间。(空闲时间大于,设定的时间是才会执行!!!)
eg:
<div id="watch-example" style="font-size: 50px"> <p> Ask a yes/no question: <input v-model="question"> </p> <p>{{ answer }}</p></div>
var watchExampleVM = new Vue({ el: '#watch-example', data: { question: '', answer: 'I cannot give you an answer until you ask a question!' }, watch: { // 如果 question 发生改变,这个函数就会运行 question: function (newQuestion) { this.answer = 'Waiting for you to stop typing...' this.getAnswer() } }, methods: { // _.debounce 是一个通过 lodash 限制操作频率的函数。 // 在这个例子中,我们希望限制访问yesno.wtf/api的频率 // ajax请求直到用户输入完毕才会发出 //参考: https://lodash.com/docs#debounce getAnswer: _.debounce( function () { var vm = this if (this.question.indexOf('?') === -1) { console.log('ttt') vm.answer = 'Questions usually contain a question mark. ;-)' return } vm.answer = 'Thinking...' axios.get('https://yesno.wtf/api') .then(function (response) { vm.answer = _.capitalize(response.data.answer) }) .catch(function (error) { vm.answer = 'Error! Could not reach the API. ' + error }) }, // 这是我们为用户停止输入等待的毫秒数 500 ) }})
1 1
- _.debounce 应用
- Underscore.js 中 _.throttle 和 _.debounce 的差异
- 浅谈 Unserscore.js 中 _.throttle 和 _.debounce 的差异
- 浅谈 Underscore.js 中 _.throttle 和 _.debounce 的差异
- 浅谈 Underscore.js 中 _.throttle 和 _.debounce 的差异
- 浅谈 Underscore.js 中 _.throttle 和 _.debounce 的差异
- 浅谈 Underscore.js 中 _.throttle 和 _.debounce 的差异
- throttle&debounce
- debounce函数
- 介绍trottle 和 debounce
- Button press & debounce
- angular debounce throttle
- javascript之debounce函数
- Rxjava(过滤类)-Debounce
- throttle and debounce
- debounce与throttle区别
- 白话debounce和throttle
- debounce与throttle区别
- ios 定时 button
- AMD Linux驱动团提供对Vega的全面支持
- 阿斯达打奥德赛
- Android-25种开源炫酷动画框架
- 201509-3 模板生成系统
- _.debounce 应用
- new创建对象的如何传递构造参数-c++
- 数据结构与算法之DFS/BFS解决扫雷问题<十五>
- python高手之路python处理excel文件(方法汇总)
- 2017河南工业大学校赛 F Hmz 的女装
- JavaEE / WEB IP String/Integer 转换规则
- 常用COM接口表
- AngularJS
- Java实现排序算法