|
@@ -1,6 +1,5 @@
|
|
// 1.引入创建store方法
|
|
// 1.引入创建store方法
|
|
import { configureStore } from "@reduxjs/toolkit";
|
|
import { configureStore } from "@reduxjs/toolkit";
|
|
-
|
|
|
|
// 计数器状态管理
|
|
// 计数器状态管理
|
|
// 方法名长一点 语义化强一点
|
|
// 方法名长一点 语义化强一点
|
|
function countManager(state={value:10},action) {
|
|
function countManager(state={value:10},action) {
|
|
@@ -9,6 +8,8 @@ function countManager(state={value:10},action) {
|
|
return {value: state.value + 1}
|
|
return {value: state.value + 1}
|
|
case 'count/reduce':
|
|
case 'count/reduce':
|
|
return {value: state.value - 1}
|
|
return {value: state.value - 1}
|
|
|
|
+ case 'count/self':
|
|
|
|
+ return {value:state.value + action.payload}
|
|
default:
|
|
default:
|
|
return state;
|
|
return state;
|
|
}
|
|
}
|
|
@@ -21,4 +22,23 @@ const store = configureStore({
|
|
|
|
|
|
|
|
|
|
// 3.抛出store
|
|
// 3.抛出store
|
|
-export default store;
|
|
|
|
|
|
+export default store;
|
|
|
|
+
|
|
|
|
+// 4.抛出需要的方法
|
|
|
|
+export function addNum() {
|
|
|
|
+ return {
|
|
|
|
+ type:'count/add'
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+export function reduceNum() {
|
|
|
|
+ return {
|
|
|
|
+ type:'count/reduce'
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export function selfNum(number) {
|
|
|
|
+ return {
|
|
|
|
+ type:"count/self",
|
|
|
|
+ payload:number
|
|
|
|
+ }
|
|
|
|
+}
|