查看: 92|回复: 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:dzh188@hotmail.com

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

在本版发帖返回顶部