看一段redux中的connect方法的参数
第一眼看上去蒙逼了吧
({ welcomeAndWorkplace: { currentUser, projectNotice, activities, radarData }, loading })
=> (
{
currentUser,
projectNotice,
activities,
radarData,
currentUserLoading: loading.effects['welcomeAndWorkplace/fetchUserCurrent'],
projectLoading: loading.effects['welcomeAndWorkplace/fetchProjectNotice'],
activitiesLoading: loading.effects['welcomeAndWorkplace/fetchActivitiesList'],
}
)
不过是解构赋值
一个更简单的demo来解释它
这是一个.vue文件
在data里return了
devicesInfo: {
windowHeight: "111"
},
在onReady执行了解构这个值
const {
devicesInfo: { hehe }
} = this._data;
console.log(hehe, "[][][][]"); //undefined
这段程序解构了data里的devicesInfo然后复制给了{hehe}
?不是的,打印出来是undefined
这样是先解构了devicesInfo然后复制给了haha
const { devicesInfo: haha } = this._data;
- {ob: Observer}
- statusBarHeight:0
- windowHeight:(…)
而这种形式是又发生了一次解构
const {
devicesInfo: { windowHeight }
} = this._data;
console.log(windowHeight, "[][][][]");//111
事情很明了了
({ welcomeAndWorkplace: { currentUser, projectNotice, activities, radarData }, loading })
解构了传入的welcomeAndWorkplace,又解构了这个welcomeAndWorkplace,解构出了currentUser, projectNotice, activities, radarData,