reducer模块化拆分中定义state和action的写法

import  {CHANNEL_GETCHANNEL,SET_ACTIVE} from '../action/acttionTypes'
// 定义频道的state
const inintChannels={
    channel:[],
    activeId:0
}
// 定义action
export const channel=(state = inintChannels, action)=> {
    // console.log('reducer:', state, action)
    switch (action.type) {
      case SET_ACTIVE:
        return {...state,activeId:action.payload}
      // 处理频道列表
      case CHANNEL_GETCHANNEL:
        return {...state,channel:action.payload}
      default:
        return state
    }
  }

上一篇:Echarts项目源代码分析


下一篇:每天五道前段面试题