如何修复组件位置从底部开始,然后在刷新页面时移动到react JS中的正常位置

发布于 2025-02-07 06:31:53 字数 639 浏览 2 评论 0原文

我的组件具有侧边栏和内容,如下所示。

当页面刷新时,第一次加载组件内容下面如下所示,在瞬间,组件恢复正常。

我在每个组件中使用Module.css。有这样的结构:

component
|___Sidebar
|   |___index.tsx
|   |___index.module.css
|___Content
    |___index.tsx
    |___index.module.css

谁能解释发生了什么?发生这种情况是因为我使用的是CSS文件夹结构,例如会导致样式迟到吗? 您如何看待这个问题可以解决?

I have a component that has a sidebar and content as shown below.

strong text

When the page is refreshed, the first time the component content is loaded below as shown below and in an instant, the components are back to normal.

enter image description here

I use module.css in every component. With a structure like this:

component
|___Sidebar
|   |___index.tsx
|   |___index.module.css
|___Content
    |___index.tsx
    |___index.module.css

Can anyone explain what happened? Is this happening because I'm using css folder structure like that which causes styles to be late to read?
How do you think this problem can be solved?

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

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

发布评论

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

评论(1

酒与心事 2025-02-14 06:31:53

选择之一是将CSS文件加载到index.js或app.js文件中,该文件是应用程序中最重要的组件。然后,您可以使用DOM事件添加类似的组件。目前,由于您没有共享任何代码,因此很难复制该问题。但是我建议值得尝试一下。确保在index.js文件中添加CSS文件

document.addEventListener("DOMContentLoaded", function(event) {
      ReactDOM.render(
        <App />,
        document.getElementById('root')
      );
    });

One of the option is to load the CSS files in the index.js or app.js file which is the top most component in your app. Then you can use the dom event to add the component like below. Currently it is difficult to reproduce the issue since you haven't shared any code. But I would suggest worth giving this a try. Make sure you add the CSS files in index.js file

document.addEventListener("DOMContentLoaded", function(event) {
      ReactDOM.render(
        <App />,
        document.getElementById('root')
      );
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文