【发布时间】:2019-11-08 18:19:11
【问题描述】:
我使用 create-react-app 创建了一个项目,我正在尝试加载图像,但我不断收到相同的解析错误。
代码如下:
1 import React, { Component } from 'react'
2 import profile from './profile.png'
3
4 class Jumbotron extends Component {
5 render() {
6 return (
7 <div className="container">
8 <JumbotronName />
9 <JumbotronImg />
10 </div>
11 )
12 }
13 }
14
15 const JumbotronName = () => {
16 return (
17 <div className="container">
18 <h1>Temp</h1>
19 </div>
20 )
21 }
22
23 const JumbotronImg = () => {
24 return (
25 <div className="container">
26 <img src{profile} alt="Profile" />
27 </div>
28 )
29 }
30
31 export default Jumbotron
两个文件(Jumbotron.js 和图像)都在 create-react-app 的 src 文件夹中。
当我使用 npm start 运行时,我得到这个解析错误
./src/Jumbotron.js
Line 26:22: Parsing error: Unexpected token, expected "..."
24 | return (
25 | <div className="container">
> 26 | <img src{profile} alt="Profile" />
| ^
27 | </div>
28 | )
29 | }
有什么想法吗?
编辑:如果我在第 26 行(ex src{...profile})的配置文件之前放置“...”,它将编译但不会加载图像
【问题讨论】:
-
您缺少等号:
<img src={profile}。标记为错字。
标签: javascript reactjs npm webpack