0

I need to update my value which is in JSON thru v-model

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

<input type="text" v-model="<what to put here?>" > //so that directly value can be update in my vue data property JSON mentioned above

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.