I'm new with Vue.js and I'm trying to test some features of this framework.
Now I'm testing the input forms, and I would like to make a one-way binding, without using the v-model directive, but I can't find any example. Anyone could help me, please?
1 Answer
Here is example of one way and two way binding
var V = new Vue({
el:'#vue-instance',
data:{
name:'Niklesh'
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.4/vue.js"></script>
<div id="vue-instance">
<div>One Way binding with input box <input type="text" :value="name"></div>
<div>One Way binding as text {{name}}</div>
<div>Two way binding : <input type="text" v-model="name"></div>
</div>
24 Comments
Nuovo 001
Ok thank you! Another question, how can I set the initial data from an asyncronous function and then get the value on submit in vue.js one-way binding?
Niklesh Raut
@Nuovo001: You need to add just like in pure javascript as by
id or name or any seelctor to to formData which you are going to post as formData.name=$("#name").val() before submit.Niklesh Raut
@Nuovo001: what is the situation to not use
v-model ?Niklesh Raut
@Nuovo001 : one way binding is to display text, and two way is for user input, its good to use two way if you are taking user input.
Niklesh Raut
@WaldemarIce : What it should be to make
two way data-binding according to doc ? |