查看: 38|回覆: 0

[Next.js] Serve Optimized Images Using the Next.js Image Component

[複製鏈接]

3

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2008-8-16
發表於 2022-5-24 17:05:00 | 顯示全部樓層 |閲讀模式

The image component from Next.js comes with excellent performance optimizations that make it worth using. It comes with improved performance, better visual stability, faster page loads, and more!

In this lesson you’ll learn how to use this component to serve both local and remote images in your Next.js app.

 

import Image from "next/image";
// You don't need to put image into `public` directory but reocmmended
// you can put images anywhere you like
// import dog.png statically
import dog from '../dog.png';
// You can load image from remote server
// but you need to config domain in next.config.js
const TWITTER_IMG_URL = "https://pbs.twing.com/profile_iamges/xxxxxxx_400x400.jpg";

const Home = () => {
    return (
        <>
            <Image src={dog} lat="cute dog" />
            <Image src={TWITTER_IMG_URL} lat="Leader" alt="profile image" width={550} height={650} />
        </>    
    )
}

 

next.config.js

module.exports = {
    images: {
        domains: ['pbs.twimg.com']
    }
}

 



来源:https://www.cnblogs.com/Answer1215/p/16306218.html
回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部