🎉 getters使用

This commit is contained in:
bunny 2025-06-19 12:58:13 +08:00
parent eb49928833
commit b878032303
2 changed files with 6 additions and 0 deletions

View File

@ -5,6 +5,11 @@ Vue.use(Vuex);
const count = {
namespaced: true,
state: { num: 1, sum: 0 },
getters: {
bigSum(state) {
return state.sum * 10;
},
},
actions: {
// 奇数相加
incrementOdd(context) {

View File

@ -1,6 +1,7 @@
<template>
<div>
<h1>当前求和为:{{ $store.state.count.sum }}</h1>
<h1>当前求和为:{{ $store.getters["count/bigSum"] }}</h1>
<select v-model.number="$store.state.count.num">
<option :value="1">1</option>
<option :value="2">2</option>