React页面不可滚动

发布于 2025-02-11 01:37:07 字数 1376 浏览 2 评论 0原文

我无法使页面可滚动该代码如下所示,我没有使用任何CSS,我仍然是新的蜜蜂,我使用了MAP函数来渲染我已经使用道具发送数据的组件因为填补空间,什么也没

import { SimpleGrid, Flex } from "@chakra-ui/react";
import React, { useEffect, useState } from "react";

import Doccard from "../../components/doccard";
import { docdata } from "./docdat";
import data from "./docdat.json";
import Navbar from "../../components/Navbar";
import axios from "axios";


const url1 = "http://localhost:7000/doctors";

function Doctors() {
  const [docdatai, setdocdatai] = useState([]);

  useEffect(() => {
    axios
      .get(url1)
      .then((Response) => {
        console.log(Response.data);
        setdocdatai(Response.data);
      })
      .catch((err) => {
        console.log("error fetching data");
      });
    console.log("fetched");
  }, []);

  return (
    <div className="scrollable-div" style={{ overflow: "scroll" }}>
      <br />
      <br />
      <SimpleGrid columns={[2, 3, 5]} spacing={"20"} mt={4} mx={10}>
        {console.log(docdatai)}
        {docdatai.map((cardinfo, index) => {
          return (
            <Doccard
              name={cardinfo.name}
              username={cardinfo.username}
              specialization={cardinfo.specialization}
            />
          );
        })}
      </SimpleGrid>
    </div>
  );
}

export default Doctors;

I am not able to make the page scrollable the code is as given below and i have not used any css i am still a new bee i have used map function to render the components i have sent the data using props thats it i am writing this because to fill space and nothing else

import { SimpleGrid, Flex } from "@chakra-ui/react";
import React, { useEffect, useState } from "react";

import Doccard from "../../components/doccard";
import { docdata } from "./docdat";
import data from "./docdat.json";
import Navbar from "../../components/Navbar";
import axios from "axios";


const url1 = "http://localhost:7000/doctors";

function Doctors() {
  const [docdatai, setdocdatai] = useState([]);

  useEffect(() => {
    axios
      .get(url1)
      .then((Response) => {
        console.log(Response.data);
        setdocdatai(Response.data);
      })
      .catch((err) => {
        console.log("error fetching data");
      });
    console.log("fetched");
  }, []);

  return (
    <div className="scrollable-div" style={{ overflow: "scroll" }}>
      <br />
      <br />
      <SimpleGrid columns={[2, 3, 5]} spacing={"20"} mt={4} mx={10}>
        {console.log(docdatai)}
        {docdatai.map((cardinfo, index) => {
          return (
            <Doccard
              name={cardinfo.name}
              username={cardinfo.username}
              specialization={cardinfo.specialization}
            />
          );
        })}
      </SimpleGrid>
    </div>
  );
}

export default Doctors;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

去了角落 2025-02-18 01:37:07

使用Overflow-Y:自动用于在内容超过DIVS设置高度时自动显示滚动。

来自zword的答案,在这里

请记住,只有当内部内容比内部的内容高时,DIV才能滚动设置高度(您可能需要将高度设置为100VH,将宽度设置为100VW,以将高度/宽度设置为屏幕的100%)。如果要使DIV X轴可滚动,请将其更改为Overflow-X:auto,如果您希望它同时进行,请使用溢出:auto

Use overflow-y:auto for displaying scroll automatically when the content exceeds the divs set height.

Answer from ZWord, here

Keep in mind, the div will only be scrollable when the content inside is taller than the set height (you may want to set the height to 100vh and the width to 100vw to set the height / width to 100% of the screen). If you want to make the div x-axis scrollable, change it to overflow-x:auto, and if you want it to do both, use overflow:auto

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文