html - 使用 Gatsby 无法在 React 上本地加载图像
问题描述
我遇到了一个奇怪的问题,如果我尝试在本地加载图像,则会出现编译错误。
这是我的编译错误:编译错误
import { Link } from 'gatsby'
import * as React from 'react'
import test from '..\images\128PxNewAcluLogo2017Svg.png'
const IndexPage = () => {
return (
<main>
<img src={test} alt="test" />
</main>
)
}
export default IndexPage
从在线资源加载图像有效。有任何想法吗?
解决方案
不要使用反斜杠(\
),像这样使用它:
import { Link } from 'gatsby'
import * as React from 'react'
import test from '../images/128PxNewAcluLogo2017Svg.png'
const IndexPage = () => {
return (
<main>
<img src={test} alt="test" />
</main>
)
}
export default IndexPage
否则,它将被解释为转义值。
推荐阅读
- sql - 在蜂巢中如何将日期转换为 MM/DD/YY 格式
- javascript - 发布 500 错误:axios 在 asp.net react 应用程序中的两个非常相似但独立的函数中表现不同
- r - 如何使用来自其他列的信息创建列
- firebase - 遍历 Array Object 以显示多个图像
- python-3.x - 在 pandas 数据帧上使用 lambda、apply 和 join 函数
- python - Pickle 编码 utf-8 问题
- java - 谁可以将所有路径打印到 txt 文件中
- core-data - 如何在 SwiftUI 的 PreviewProvider 中编写示例模型对象?
- python - 从列表中随机选择时如何在字符串中使用变量?
- database - 在大型数据库中如何处理删除?