-
当前求和为: {{$store.state.sum}}
+ 当前求和为: {{ sum }}
+ 当前求和放大10倍后为: {{ bigSum }}
+ 我在{{ school }},学{{ subject }}
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/20_脚手架/vue_code/src/store/index.js b/20_脚手架/vue_code/src/store/index.js
index f4061aa..e7a1f9a 100644
--- a/20_脚手架/vue_code/src/store/index.js
+++ b/20_脚手架/vue_code/src/store/index.js
@@ -32,7 +32,16 @@ const mutations = {
}
//准备state-用于存储数据
const state = {
- sum: 0
+ sum: 0,
+ school: '修仙学院',
+ subject: '修仙'
+}
+
+// getters 用于对state中的数据进行加工,类似用computed
+const getters = {
+ bigSum(state) {
+ return state.sum * 10
+ }
}
// 创建并导出store
@@ -40,4 +49,5 @@ export default new Vuex.Store({
actions,
mutations,
state,
+ getters
})