vue 2.0 debounce已经被移除
参考文档:
https://cn.vuejs.org/v2/guide/migration.html#替换-debounce-过滤器
https://vuejs.org/v2/guide/migration.html#debounce-Param-Attribute-for-v-model-removed
完整代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>vue-循环重复</title> <script src="https://unpkg.com/vue@2.5.9/dist/vue.js"></script> <script src="https://unpkg.com/lodash@4.13.1/lodash.min.js"></script> </head> <body> <div id="box"> <input type="button" @click="add" value="添加"> <ul> <li v-for="val in arr"> [[val]] </li> </ul> </div> <script> var vm = new Vue({ delimiters: ['[[', ']]'], el: '#box', data: { arr: ['apple', 'pear', 'grape'] }, methods: { add: _.debounce(function () { this.arr.push('tomato') }, 1000) } }) </script> </body> </html>
在使用官方的'_.debounce()时要导入:
<script src="https://unpkg.com/lodash@4.13.1/lodash.min.js"></script>
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!