vue加减法
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title><script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>&l
·
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<style>
</style>
</head>
<body>
<div id="app">
您点击了 {{count}} 次 ,奇偶判断: {{qiOu}}<br/>
<button @click="tianjia">+</button>
<button @click="jianshao">-</button>
</div>
<script>
var vue = new Vue({
el: "#app",
data() {
return {
count: 0
}
},
computed: {
qiOu() {
return this.count % 2 == 0 ? "偶数" : "奇数";
}
},
methods: {
tianjia() {
this.count = ++this.count;
},
jianshao() {
var zhi = this.count - 1;
if (zhi <= 0) {
zhi = 0;
}
this.count = zhi;
}
}
});
</script>
</body>
</html>
FR:徐海涛(hunk Xu)
QQ技术交流群:386476712
更多推荐
已为社区贡献6条内容
所有评论(0)