最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Parseint in vuejs method - Stack Overflow

programmeradmin1浏览0评论

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;
  }
}},

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;
  }
}},
Share Improve this question asked Dec 1, 2019 at 21:12 aravinvafshearavinvafshe 2872 gold badges5 silver badges13 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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)
发布评论

评论列表(0)

  1. 暂无评论