A
A
andrei_pro2019-06-15 18:01:46
JavaScript
andrei_pro, 2019-06-15 18:01:46

Binding form value by timeout?

Hello.
There is a form with text stored in vuex: There is a v-model binding
<textarea v-model="text"></textarea>

computed: {
        text: {
                get() {
                    return this.product.text
                },
                set(value) {
                    this.$store.dispatch(`updateProduct`, value)
                }
            },
}

Problem: when editing a test, there are dozens of updateProduct events, I need to somehow combine them and save them by timeout - every 2 seconds, for example

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2019-06-15
@andrei_pro

throttle :

computed: {
  text: {
    get() {
      // ...
    },
    set: _.throttle(function(text) {
      // здесь вызываете мутацию
    }, 2000),
  },
},

https://jsfiddle.net/hjub5swz/

A
aloky, 2019-06-15
@aloky

debounce won't help?

C
coderisimo, 2019-06-15
@coderisimo

https://medium.com/@modex13/vue-js-2-throttle-b43d...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question