system-copyright-react/src/store/index.ts

34 lines
824 B
TypeScript
Raw Normal View History

2024-08-12 14:43:58 +08:00
import { createStore } from "redux"
2024-07-31 16:00:30 +08:00
// 设置数据
const baseState = {
2024-08-12 14:43:58 +08:00
// msg: '嘻嘻嘻嘻嘻嘻',
// num: 10,
// shuju: {
// name: '小白',
// hobby: '吃饭',
// val: ''
// },
belongArray: []
2024-07-31 16:00:30 +08:00
}
// 创建仓库
2024-08-12 14:43:58 +08:00
const reducer = (state = baseState, action: any) => {
const nstate: any = JSON.parse(JSON.stringify(state))
// if (action.type == "numadd") {
// nstate.num++
// // console.log('123');
// }
// if (action.type == 'new') {
// nstate.shuju.val = action.val
// console.log(nstate.shuju.val);
// }
2024-07-31 16:00:30 +08:00
// redux 要求 state必须深拷贝一次 才能返回
2024-08-12 14:43:58 +08:00
if (action.type == 'uparray') {
2024-07-31 16:00:30 +08:00
nstate.belongArray = action.val
}
return nstate
}
const store = createStore(reducer)
export default store