|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
<template> |
|
|
|
|
<div> |
|
|
|
|
<h1>当前求和为: {{sum}}</h1> |
|
|
|
|
<h1>当前求和为: {{$store.state.sum}}</h1> |
|
|
|
|
<select v-model.number="n"> |
|
|
|
|
<option value="1">1</option> |
|
|
|
|
<option value="2">2</option> |
|
|
|
@ -18,8 +18,7 @@ export default { |
|
|
|
|
name: "Count", |
|
|
|
|
data() { |
|
|
|
|
return { |
|
|
|
|
n: 1, |
|
|
|
|
sum: 0 |
|
|
|
|
n: 1 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
mounted() { |
|
|
|
@ -27,20 +26,16 @@ export default { |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
add() { |
|
|
|
|
this.sum += this.n |
|
|
|
|
this.$store.commit('vuexAdd', this.n) |
|
|
|
|
}, |
|
|
|
|
sub() { |
|
|
|
|
this.sum -= this.n |
|
|
|
|
this.$store.commit('vuexSub', this.n) |
|
|
|
|
}, |
|
|
|
|
addOdd() { |
|
|
|
|
if (this.sum % 2) { |
|
|
|
|
this.sum += this.n |
|
|
|
|
} |
|
|
|
|
this.$store.dispatch('vuexAddOdd', this.n) |
|
|
|
|
}, |
|
|
|
|
addWait() { |
|
|
|
|
setTimeout(()=>{ |
|
|
|
|
this.sum += this.n |
|
|
|
|
}, 500) |
|
|
|
|
this.$store.dispatch('vuexAddWait', this.n) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|