|
|
@ -1,19 +1,23 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<h1>当前求和为: {{$store.state.sum}}</h1> |
|
|
|
<h1>当前求和为: {{ sum }}</h1> |
|
|
|
|
|
|
|
<h3>当前求和放大10倍后为: {{ bigSum }}</h3> |
|
|
|
|
|
|
|
<h3>我在{{ school }},学{{ subject }}</h3> |
|
|
|
<select v-model.number="n"> |
|
|
|
<select v-model.number="n"> |
|
|
|
<option value="1">1</option> |
|
|
|
<option value="1">1</option> |
|
|
|
<option value="2">2</option> |
|
|
|
<option value="2">2</option> |
|
|
|
<option value="3">3</option> |
|
|
|
<option value="3">3</option> |
|
|
|
</select> |
|
|
|
</select> |
|
|
|
<button @click="add">+</button> |
|
|
|
<button @click="add(n)">+</button> |
|
|
|
<button @click="sub">-</button> |
|
|
|
<button @click="sub(n)">-</button> |
|
|
|
<button @click="addOdd">当前求和为奇数再加</button> |
|
|
|
<button @click="addOdd(n)">当前求和为奇数再加</button> |
|
|
|
<button @click="addWait">等一等再加</button> |
|
|
|
<button @click="addWait(n)">等一等再加</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
<script> |
|
|
|
|
|
|
|
import {mapState, mapGetters, mapMutations, mapActions} from "vuex"; |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
export default { |
|
|
|
name: "Count", |
|
|
|
name: "Count", |
|
|
|
data() { |
|
|
|
data() { |
|
|
@ -24,24 +28,25 @@ export default { |
|
|
|
mounted() { |
|
|
|
mounted() { |
|
|
|
console.log('Count', this) |
|
|
|
console.log('Count', this) |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
add() { |
|
|
|
...mapMutations({add:'vuexAdd', sub:'vuexSub'}), // 对象写法 |
|
|
|
this.$store.commit('vuexAdd', this.n) |
|
|
|
// ...mapMutations(['vuexAdd', 'vuexSub']), //数组写法 |
|
|
|
}, |
|
|
|
|
|
|
|
sub() { |
|
|
|
...mapActions({addOdd:'vuexAddOdd', addWait:'vuexAddWait'}), |
|
|
|
this.$store.commit('vuexSub', this.n) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
addOdd() { |
|
|
|
|
|
|
|
this.$store.dispatch('vuexAddOdd', this.n) |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
addWait() { |
|
|
|
|
|
|
|
this.$store.dispatch('vuexAddWait', this.n) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
computed: { |
|
|
|
|
|
|
|
...mapState(['sum', 'school', 'subject']), // 数组写法 |
|
|
|
|
|
|
|
// ...mapState({sum: 'sum', school: 'school', subject: 'subject'}), // 对象写法 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...mapGetters({bigSum: 'bigSum'}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
|
|
<style> |
|
|
|
<style> |
|
|
|
button {margin-left: 5px} |
|
|
|
button { |
|
|
|
|
|
|
|
margin-left: 5px |
|
|
|
|
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |