在try 使用来自‘Next/Image’的Image组件显示来自Localhost:8081的图像时,我在Next.js 14项目中遇到错误.后端是Java,它发送图像.
下面是我使用Image组件的代码片段:
'use client'
import Image from 'next/image'
export default function Home() {
return (
<div className='flex items-center justify-center min-h-screen'>
<Image
src={'http://localhost:8081/api/image/get/1'}
alt='image'
width={200}
height={200}
/>
Hello world!!!
</div>
)
}
当我使用常规标记时,不会出现错误.
我try 按如下方式配置我的next.config.mjs:
/** @type {import('next').NextConfig} */
const nextConfig = {
image: {
remotePatterns: [
{
protocol: 'http',
hostname: 'localhost',
port: '8081',
pathname: '/api/image/get/**',
},
],
},
}
export default nextConfig