[Vuejs]-How to set default value on dynamic input fields in Vue.js?

3👍

As Vue js is reactive you can simply set initial value in result

 new Vue({
      el: '#app',
      data: {
        result: ["1","1","1"],
        array: [{
            id: 1
        }, {
            id: 2
        }, {
            id: 3
        }]
      }
    })

1👍

According to the official documentation,

v-model will ignore the initial value, checked or selected attributes
found on any form elements. It will always treat the Vue instance data
as the source of truth. You should declare the initial value on the
JavaScript side, inside the data option of your component.

I think it is a design decision of Vue to use the benefit of Vue instance’s reactive system rather than listening to DOM updates when such attributes are updated.

So you can put directly your default values into the result array, here’s the updated working jsfiddle.

👤Sense

Leave a comment