🎉 getters使用
This commit is contained in:
parent
eb49928833
commit
b878032303
|
@ -5,6 +5,11 @@ Vue.use(Vuex);
|
||||||
const count = {
|
const count = {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: { num: 1, sum: 0 },
|
state: { num: 1, sum: 0 },
|
||||||
|
getters: {
|
||||||
|
bigSum(state) {
|
||||||
|
return state.sum * 10;
|
||||||
|
},
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
// 奇数相加
|
// 奇数相加
|
||||||
incrementOdd(context) {
|
incrementOdd(context) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<h1>当前求和为:{{ $store.state.count.sum }}</h1>
|
<h1>当前求和为:{{ $store.state.count.sum }}</h1>
|
||||||
|
<h1>当前求和为:{{ $store.getters["count/bigSum"] }}</h1>
|
||||||
<select v-model.number="$store.state.count.num">
|
<select v-model.number="$store.state.count.num">
|
||||||
<option :value="1">1</option>
|
<option :value="1">1</option>
|
||||||
<option :value="2">2</option>
|
<option :value="2">2</option>
|
||||||
|
|
Loading…
Reference in New Issue