javascript - VueJS v-model value in to another input - Stack Overflow

I have two inputs, first:<input v-model="from_amount" id="from_amount" type=&quo

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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

You 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

相关推荐

  • javascript - VueJS v-model value in to another input - Stack Overflow

    I have two inputs, first:<input v-model="from_amount" id="from_amount" type=&quo

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信