// 这是reducer
export const requestUserInfo = (state = {}, action) => {
switch(action.type) {
case 'HEADER_RECEIVE_USERINFO':
console.log(action.data)// 有值
return Object.assign({}, state, action.data)
break
default:
return state
}
}
// 这是action
function receiveUserInfo (data) {
return {
type: 'HEADER_RECEIVE_USERINFO',
data
}
}
export function requestUserInfo () {
return dispatch => {
return axios.post('/user/getScores', qs.stringify({
token: token,
uid: uid
}))
.then(res => {
if(res.data.status !== 200) {
message.error(res.data.message)
return state
}
return { ...res.data.attachment}
})
.then(data => {
dispatch(receiveUserInfo(data))
})
}
}
Both action and reducer can be executed normally. I monitored the store in the router, but the store has never changed. Did I write something wrong somewhere?
Someone help me, I've been stuck on this problem all day, I don't know where the problem is
Object.assign is a shallow copy and will only process the first layer
state = {
}
Is the return value of your action.data an object?