Reputation: 287
for example lets take this.last
to be 5 and this.current
60 , I want this.last
+ this.current
to be 65 and not 60 5. I tried parseInt(this.last + this.current)
but it's not working
<button class="plus" @click="plus">+</button>
<input class="res" v-model="current" maxlength="24" disabled>
<input class="res2" v-model="last" maxlength="24" disabled>
button{
width:200px;
height:200px;
}
data:{
last: null,
current: " ",
plusClicked: false
}
methods:{
plus:function(){
this.last = this.current;
this.current = " ";
this.plusClicked = true;
},
equal:function(){
if(this.plusClicked == true){
alert(parseInt(this.last + this.current));
this.plusClicked = !true;
}
}},
Upvotes: 2
Views: 10167
Reputation: 2052
First, don't initialize this.current
to " "
but to 0
.
You should also change the type of the input field to <input type="number">
.
To add both numbers use:
parseInt(this.last) + parseInt(this.current)
Upvotes: 6