在 ReactJs 中为组件创建不同的移动布局
Creating Different mobile layout for a component in ReactJs
我们如何使用 ReactJs 为组件(具有不同的桌面类型布局)创建完全不同的(移动类型布局)。
(无响应,响应是 css 必须处理的事情。)
它应该是组件的不同布局,即这里为桌面屏幕创建一个带有菜单(header 菜单)的页面,它成为小屏幕上带有徽标的导航侧边栏。
老实说,简单的响应式 css 布局可能是最好的解决方案,但步骤是
1) 在 JS 中检测用户是在移动设备还是桌面设备上。例如这个问题有一个很好的建议作为答案:Detecting a mobile browser
2) 使用它来决定在你的根组件中使用哪个布局:
function isMobile() {
// some js way to detect if user is on a mobile device
}
class Root extends Component {
render() {
return isMobile() ? ( <MobileLayout /> ) : ( <DesktopLayout /> )
}
}
结帐react-responsive,您可以使用媒体查询根据设备大小呈现不同的组件。
我们如何使用 ReactJs 为组件(具有不同的桌面类型布局)创建完全不同的(移动类型布局)。 (无响应,响应是 css 必须处理的事情。) 它应该是组件的不同布局,即这里为桌面屏幕创建一个带有菜单(header 菜单)的页面,它成为小屏幕上带有徽标的导航侧边栏。
老实说,简单的响应式 css 布局可能是最好的解决方案,但步骤是
1) 在 JS 中检测用户是在移动设备还是桌面设备上。例如这个问题有一个很好的建议作为答案:Detecting a mobile browser
2) 使用它来决定在你的根组件中使用哪个布局:
function isMobile() {
// some js way to detect if user is on a mobile device
}
class Root extends Component {
render() {
return isMobile() ? ( <MobileLayout /> ) : ( <DesktopLayout /> )
}
}
结帐react-responsive,您可以使用媒体查询根据设备大小呈现不同的组件。