You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

52 lines
904 B

<template>
<div>
<h1>当前求和为: {{sum}}</h1>
<select v-model.number="n">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<button @click="add">+</button>
<button @click="sub">-</button>
<button @click="addOdd">当前求和为奇数再加</button>
<button @click="addWait">等一等再加</button>
</div>
</template>
<script>
export default {
name: "Count",
data() {
return {
n: 1,
sum: 0
}
},
mounted() {
console.log('Count', this)
},
methods: {
add() {
this.sum += this.n
},
sub() {
this.sum -= this.n
},
addOdd() {
if (this.sum % 2) {
this.sum += this.n
}
},
addWait() {
setTimeout(()=>{
this.sum += this.n
}, 500)
}
}
}
</script>
<style>
button {margin-left: 5px}
</style>