简体   繁体   English

我的组件只在笔记本电脑和台式机上呈现,在手机上不呈现

[英]my component only renders on laptops and desktops but not mobile phones

first of all I would like to say thank you in advance to everyone who invest their time to help me figure this out.首先,我想提前感谢所有花时间帮助我解决这个问题的人。

I'm currently building an app and everything is rendering just as fine, except for one component;我目前正在构建一个应用程序,除了一个组件外,一切都呈现得很好; in this component I'm using Axios to make a GET request to my server.在此组件中,我使用 Axios 向我的服务器发出 GET 请求。 everything is working correctly on the backend, my server responds with the requested information in Json format, and the component that made the request is successfully receiving the requested data.后端一切正常,我的服务器以 Json 格式响应请求的信息,发出请求的组件成功接收请求的数据。

now here's where my problem comes in, after I've retrieved that data I want to loop through it (because it's an Array) with the.map() function and return a component with the mapped out data;现在我的问题来了,在我检索到数据后,我想使用 the.map() function 循环遍历它(因为它是一个数组)并返回一个包含映射数据的组件; I've written the code to do this already and when I visit the app on a laptop or desktop device the component renders perfectly, just as I expected it to, but when I visit the app on a mobile device the component does not render.我已经编写了执行此操作的代码,当我在笔记本电脑或台式机设备上访问该应用程序时,组件呈现得非常完美,正如我预期的那样,但是当我在移动设备上访问该应用程序时,该组件不会呈现。 the component gets stuck on the loading status and never actually renders the component.该组件卡在加载状态并且从未真正呈现该组件。

what makes this more difficult to resolve is that the fact that I'm not getting any error messages from the app, not from the server side nor from google chrome's devTools.使这个问题更难解决的是,我没有从应用程序中收到任何错误消息,而不是从服务器端或谷歌浏览器的 devTools 中收到错误消息。 so I don't know how to approach this and resolve this issue.所以我不知道如何处理这个问题并解决这个问题。 so, my question is, how do I get the component to render on all devices including mobile phones and iPads, not just laptops and desktops?所以,我的问题是,如何让组件在包括手机和 iPad 在内的所有设备上呈现,而不仅仅是笔记本电脑和台式机?

here are my codes for the component:这是我的组件代码:

const [productData, setProductData] = useState([]);

    useEffect(() => {
        window.addEventListener("resize", screenSize);
        assetStatusHandler();
        const url = "http://my-web-address.com/api/guest/promotional-products/real-estate";
        axios
            .get(url)
            .then((res) => {                
                // console.log(res);
                console.log(res.data);
                setProductData(res.data);
            })
            .catch((err) => {               
                console.error(err);
            });
        return () => {
            window.addEventListener("resize", screenSize);
        };
    }, []);

const dynamicComponents = (data) => {
    if (data.length <= 0) {
        return (
            <div className="page-section__loader_container">
                <Spinner className="page-section__loading-status" animation="border" role="status">
                    <span className="visually-hidden">Loading...</span>
                </Spinner>
                    <h1>loading ...</h1>
            </div>
            );
        } else {
            const products = productData.map((property, i) => {
                return <RevolvingCard key={i} image={`${firstProperty} 640w, ${firstPropertyMedium} 1000w, ${firstPropertyLarge} 1500w`} overlay={i % 2 ? "Deal Available" : "Deal Sold"} text={"property.Info"} button={revolvingCardHandler} backButton1={acquireDealHandler} backButton2={cancelDealHandler} title={`${property.address.formatted_street_address}, ${property.address.city}, ${property.address.state}, ${property.address.zip_code}`} />;
            });
            return products;
        }
    };

return (
        <div className="page-section wrapper" id="real-estate">
            <h1 className="page-section__section-title">real estate market</h1>
            <div className="page-section__display-container">{dynamicComponents(productData)}</div>
            {activateOverlay && <div className="page-section__large-screen-overlay"></div>}
        </div>
    );

This could be an issue of not having open permissions to access the server from your mobile device.这可能是因为您没有打开移动设备访问服务器的权限的问题。 If you're trying to access a server that is only serving data within the LAN, your phone may just be accessing it from outside the LAN.如果您尝试访问仅在 LAN 内提供数据的服务器,则您的手机可能只是从 LAN 外部访问它。 Try turning off mobile data and connecting to your wifi on your phone.尝试关闭移动数据并连接到手机上的 wifi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM