vue.js default value, how to add it
善為
善為 2019-01-31 11:52:11
0
2
1187
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>

<div id="box">
input里面输入值,从而改变结果<br>
{{num1}}+<input type="text" v-model="num2">={{num3}}
</div>
<script src="js/Vue.js"></script>
<script>
new Vue({
el:'#box',
data:{
num1:'1',
num2:'2',
num3:''
},
watch:{
num2:function(){
return this.num3=Math.floor(this.num1)+Math.floor(this.num2);

}
}
})
</script>
</body>
</html>


2019-01-31_115118.pngThe default is like this. How can I directly output the value of num3 when opening the page?

善為
善為

reply all(1)
Peter-Zhu

To convert the numbers in the string to numeric type, you should use parseInt() / parseFloat()

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template