Reputation: 7128
I have numeric input field and I'd like to return some results while user is filling the input field.
<input type="number" name="bid" v-model="bid.bid" class="form-control">
example:
PS: The reason that I didn't share any
watch, mounted, etc.
code is because i don't have any code for this question.
any idea?
Upvotes: 0
Views: 80
Reputation: 433
You can use a computed property for that :
new Vue({
el: "#app",
data: {
bid: 1000
},
computed: {
reducedBid() {
return this.bid * 0.9
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<input type="number" name="bid" v-model="bid" class="form-control">
<p>You get {{ reducedBid }}</p>
</div>
Here is a resource on computed properties.
Hope it helps!
Upvotes: 0
Reputation: 181
This is a very simple snippet. Hope it would be useful.
var app = new Vue({
el: '#app',
data: {
bid: 0
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
your bid: <input type="number" name="bid" v-model.number="bid" class="form-control">
<br>
your result: <span>{{bid*0.9}}</span>
</div>
Upvotes: 0
Reputation: 7220
You can insert the value directly into the page pretty easily using interpolation:
<div>You get: {{bid.bid * 0.9}}</div>
Upvotes: 1