I have two inputs, first:
<input v-model="from_amount" id="from_amount" type="text" class="form-control" name="from_amount">
And the second:
<input id="from_amount" type="text" class="form-control" name="to_amount" value="@{{ from_amount }}">
If i type number in from_amount
it should be outputted in to_amount
Here's my VueJS code:
var request = new Vue({
el: '#request-creator',
data: {
from_amount: '',
to_amount: ''
},
puted: {
calculate: function() {
return (this.from_amount * 750) / 0.00024
}
}
})
But seems like it's impossible to do with Vue?
I have two inputs, first:
<input v-model="from_amount" id="from_amount" type="text" class="form-control" name="from_amount">
And the second:
<input id="from_amount" type="text" class="form-control" name="to_amount" value="@{{ from_amount }}">
If i type number in from_amount
it should be outputted in to_amount
Here's my VueJS code:
var request = new Vue({
el: '#request-creator',
data: {
from_amount: '',
to_amount: ''
},
puted: {
calculate: function() {
return (this.from_amount * 750) / 0.00024
}
}
})
But seems like it's impossible to do with Vue?
Share asked Dec 1, 2016 at 6:45 Alexander KimAlexander Kim 18.4k24 gold badges107 silver badges165 bronze badges2 Answers
Reset to default 6You need to use v-bind, to bind puted property to an input field like following:
<input id="from_amount" type="text" class="form-control" name="to_amount" v-bind:value="calculatedFromAmount">
or in short, you can also write
... :value="calculatedFromAmount">
See Working fiddle: http://jsfiddle/bvr9754h/
You have to define puted property like following in due ponent:
puted: {
calculatedFromAmount: function() {
return (this.from_amount * 750) / 0.00024
}
}
it's very possible.
Modify your code so that to_amount
is the name of the puted property :
var request = new Vue({
el: '#request-creator',
data: {
from_amount: '',
},
puted: {
to_amount: function() {
return (this.from_amount * 750) / 0.00024
}
}
})
and the html to :
<input id="from_amount" type="text" class="form-control" name="to_amount" :value="to_amount">
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742267132a4412012.html
评论列表(0条)