How to temporize the analysis of an <input> field?

后端 未结 1 721
春和景丽
春和景丽 2021-01-12 13:12

I would like to analyze the content of an field when there is no user activity.

I will take below a simple example (counting the number o

1条回答
  •  庸人自扰
    2021-01-12 13:35

    That works the way it is supposed to. As it is said in the docs:

    It will update any bindings that depend on computed property when the original data changes

    But there's a way to do it:

    var app = new Vue({
      el: '#root',
      data: {
        message: '',
        messageLength:  0
      },
      methods: {
        len: _.debounce(
          function() {
            this.messageLength = this.message.length
          }, 
          300 // time
        )
      }
    })
    
     
    
    Length: {{ messageLength }}

    Full example: https://vuejs.org/v2/guide/computed.html#Watchers

    p.s. A comment about computed being sync from the vue's author: https://forum-archive.vuejs.org/topic/118/throttle-computed-properties/3

    p.p.s Classics article about difference between debounce and throttle.

    0 讨论(0)
提交回复
热议问题