当前位置:主页 > 网页前端 > vue >

vue之debounce属性被移除及处理详解

时间:2021-03-18 09:46:12 | 栏目:vue | 点击:

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>

您可能感兴趣的文章:

相关文章