小编ang*_*elo的帖子

如何在 NextJS Image 组件中运行图像的 onLoad 函数

我想在加载图像时显示骨架。我尝试在 NextJS 提供的onLoadImage组件中传递一个 prop,但该函数在加载图像之前触发。

这是我的代码

const [loaded, setLoaded] = useState(false);

<Image
  src={src}
  alt={""}
  className={styles.image_tag}
  onLoad={(e) => setLoaded(true)}
  style={{ opacity: loaded ? "1" : "0" }}
  layout={"fill"}
/>

{!loaded && (
  <Skeleton
    className={styles.skeleton}
    variant={"rect"}
    animation={"wave"}
  />
)}
Run Code Online (Sandbox Code Playgroud)

image reactjs next.js nextjs-image

10
推荐指数
1
解决办法
2万
查看次数

如何在 NextJS 中创建轮播?

我正在尝试构建一个旋转木马,就像亚马逊主页上的一样。我将 React Bootstrap 用于轮播,但它似乎不起作用。它只是像在列中一样堆叠每个项目。

<Carousel>
                <Carousel.Item>
                    <img src={'https://images-na.ssl-images-amazon.com/images/G/01/AmazonExports/Fuji/2020/October/Fuji_Tallhero_Dash_en_US_1x._CB418727898_.jpg'} alt="" />
                </Carousel.Item>

                <Carousel.Item>
                    <img src={'https://images-na.ssl-images-amazon.com/images/G/01/AmazonExports/Events/2020/PrimeDay/Fuji_TallHero_NonPrime_v2_en_US_1x._CB403670067_.jpg'} alt="" />
                </Carousel.Item>
            </Carousel>
Run Code Online (Sandbox Code Playgroud)

答案中接受使用 React Bootstrap 以外的任何其他框架的代码。

carousel reactjs react-bootstrap next.js

4
推荐指数
1
解决办法
9959
查看次数

如何为 next.js 中的每个页面使用 getServerSideProps?

我已经设置了一个带有 nookies 的 cookie,它存储用户选择的所有产品的值。我想使用 getServerSideProps 在服务器端获取 cookie 并将值作为道具传递。我必须在所有页面上显示 cookie 的值。

当我在 _app.js 中尝试 getServerSideProps 时。它没有工作,甚至没有运行代码。

有什么办法吗?

cookies next.js getserversideprops

3
推荐指数
2
解决办法
4031
查看次数

如何在下一个js中使用auth0登录?

如何使用 auth0 登录下一个 js 应用程序?我按照 auth0 网站的快速入门进行操作,但在登录页面上收到此错误。

<a href="/api/auth/login">Login</a>

这是pages/api/[...auth0].js

import { handleAuth } from '@auth0/nextjs-auth0';

export default handleAuth();

Run Code Online (Sandbox Code Playgroud)

我在登录页面上收到此错误。

登录时出错

我在我的终端中得到了这个

OPError: expected 200 OK, got: 404 Not Found
    at processResponse (/home/madhav/Documents/Web Development/freelancing/frontend-affilboost/node_modules/openid-client/lib/helpers/process_response.js:48:11)
    at Function.discover (/home/madhav/Documents/Web Development/freelancing/frontend-affilboost/node_modules/openid-client/lib/issuer.js:252:22)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  error: 'expected 200 OK, got: 404 Not Found'
}

Run Code Online (Sandbox Code Playgroud)

我正在Failed to load resource, the server responded with code 500进入浏览器的控制台。

我究竟做错了什么?

reactjs auth0 next.js

3
推荐指数
1
解决办法
1621
查看次数