order.ts
707 字节
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getTopBanner } from '@/api'
export const fetchOrderDataAction = createAsyncThunk(
'fetchdata',
(payload, { dispatch }) => {
// 1.顶部的banners
getTopBanner().then((res: any) => {
dispatch(changeBannerAction(res.banners))
})
return null
}
)
const orderSlice = createSlice({
name: 'order',
initialState: {
count: 100,
message: 'hello Redux',
name: 'HachimanC',
bannersList: []
},
reducers: {
changeBannerAction(state, { payload }) {
state.bannersList = payload
}
}
})
export default orderSlice.reducer
export const { changeBannerAction } = orderSlice.actions