例如让 this.last
为 5 和 this.current
60 ,我想要 this.last
+ this .current
为 65 而不是 60 5. 我尝试了 parseInt(this.last + this.current)
但它不起作用
<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;
}
}},
最佳答案
首先,不要初始化this.current
至 " "
但到0
.
您还应该将输入字段的类型更改为 <input type="number">
.
要将两个数字相加,请使用:
-
parseInt(this.last) + parseInt(this.current)
关于javascript - vuejs方法中的Parseint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59130031/