Reactjs JSS Obj-引用同一父对象中另一个属性的属性值
我得到了一个材质ui AppBar组件,它的位置为position=“fixed”,因此它作为主manu栏粘贴到窗口的上边框。这里的组件名是“header”,它使用这个JSS obj进行样式化 由于主容器在AppBar组件下滑动到顶部0,因此当其位置固定时,我需要在AppBar的正下方留出顶部向下的边距,以便它们连续定位 最好,我想设置边距顶部,使其具有AppBar高度的实际值,这样我就不需要手动设置。(AppBar高度也会根据其内容进行调整,因此大小可能会有所不同) 但是我不知道怎么做,所以我必须手动设置高度/边距顶部(主容器) 至少:如何使main_horizontal_container.marginTop从header.height中获取其值,因此只需设置一次 不幸的是,这不符合计划-“TypeError:无法读取未定义的属性'height'”Reactjs JSS Obj-引用同一父对象中另一个属性的属性值,reactjs,material-ui,jss,Reactjs,Material Ui,Jss,我得到了一个材质ui AppBar组件,它的位置为position=“fixed”,因此它作为主manu栏粘贴到窗口的上边框。这里的组件名是“header”,它使用这个JSS obj进行样式化 由于主容器在AppBar组件下滑动到顶部0,因此当其位置固定时,我需要在AppBar的正下方留出顶部向下的边距,以便它们连续定位 最好,我想设置边距顶部,使其具有AppBar高度的实际值,这样我就不需要手动设置。(AppBar高度也会根据其内容进行调整,因此大小可能会有所不同) 但是我不知道怎么做,所以我
在
this.header.height
中,似乎this
指的是没有header
的主水平容器。相反,您可以将标题
提取到变量:
const styles = theme => {
const header = {
height: 64,
};
return ({
main_horizontal_container:{
display: "flex",
get marginTop () {return header.height}
},
header,
sidebar:{
//flexBasis: content,
},
content: {
flexGrow: 1,
backgroundColor: theme.palette.background.default,
padding: theme.spacing.unit * 3,
minWidth: 0, // So the Typography noWrap works
},
toolbar: theme.mixins.toolbar,
});
}
好的,谢谢-不知道为什么没有直接相互引用的解决方案。
const styles = theme => {
const header = {
height: 64,
};
return ({
main_horizontal_container:{
display: "flex",
get marginTop () {return header.height}
},
header,
sidebar:{
//flexBasis: content,
},
content: {
flexGrow: 1,
backgroundColor: theme.palette.background.default,
padding: theme.spacing.unit * 3,
minWidth: 0, // So the Typography noWrap works
},
toolbar: theme.mixins.toolbar,
});
}