[Vuejs]-How update nested object array value directly by v-model in VUE?

1👍

Cant do it directly with v-model, unless you want to change your input type to maybe multi select.
If you really want the exact output, can listen onchange event like below.
Or can just use v-model and enter your data as you want…but will need to convert to array.

const jsonData = { class: "data.child",
    "myform.input1": [true, "<input1 value>"],
    "myform.input2": [true, "<input1 value>"]
}


const App = {
template: `<div>
<input type="text" v-model="data['myform.input2']"/>
<input type="text" @change="update"/>
<p>{{JSON.stringify(data, null, 2)}}</p>
</div>`,
methods: {
update: function(event) {
this.data['myform.input1'] = [true, event.target.value];
}
}
,
data(){
return {data: jsonData}
}
}

new Vue({
render: h => h(App),
}).$mount("#app");
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">
</div>
👤Mosd

Leave a comment