用Vue.js写一个整数相加的实例

Original 2019-04-11 00:55:40 330
abstract:注意:1.双向绑定值要用v-model.number指明为数值型,不然用+号就是连接作用<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><script src=&qu

注意:1.双向绑定值要用v-model.number指明为数值型,不然用+号就是连接作用

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Document</title>

<script src="vue.js"></script>

</head>

<body>

<div id="box">

请输入数字x:<input type="text" v-model.number="x"><br>

请输入数字y:<input type="text" v-model.number="y"><br>


当前x的值:<p>{{x}}</p>

当前y的值:<p>{{y}}</p>

合计是:<p :style="res">{{total}}</p>

</div>



<script>

new Vue({

//设置挂载点

el: '#box',

//页面中的数据Model

data: {

x: '',

y: '',

res: 'color:red'

},

computed: {

total:function () {

                return (this.x+this.y); 

                    }

}

})


</script>

</body>

</html>


Release Notes

Popular Entries