import { createSlice } from '@reduxjs/toolkit' type CacheKey = string type CacheVal = any const initCache = new Map([]) // 创建一个slice export const cacheSlice = createSlice({ name: 'cache', // 初始化数据状态 initialState: {}, // 定义改变数据状态的方法 reducers: { addCache(state, { payload }) { state = {...state, ...payload} return state } } }) export const { addCache } = cacheSlice.actions export default cacheSlice.reducer