将页面设置为子页面.md 648 B

将页面设置为子页面(条件渲染)

步骤:

1. 修改 src/pages/Home.jsx

  • 添加:import Devices from './Devices/Devices';
  • HomeLogic() 中获取:const { showDevices, setShowDevices } = HomeLogic();
  • 在 return 中添加:{showDevices && <Devices />} 和按钮控制显示/隐藏

2. 修改 src/pages/Home.js

  • 添加:import { useState } from 'react';
  • HomeLogic 中添加:const [showDevices, setShowDevices] = useState(false);
  • return 中暴露:showDevices, setShowDevices

3. 修改 src/App.jsx

  • 删除 Devices 的 import 和组件使用