无法使用webapck加载图像,做出反应

时间:2020-07-28 03:52:46

标签: reactjs webpack

我在react项目中使用了webpack,但是未加载图像 控制台中的错误是找不到图像 GET http:// localhost:3000 / assets / images / test.jpg 404(未找到)

      {
        test: /\.(png|jpe?g|gif)$/i,
        loader: 'file-loader',
        options: {
          name: '[path][name].[ext]',
        },
      },

这是我的webpack配置

import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'

const path = '/../../assets/images/test.jpg'

class DashboardContainer extends Component {
  handleSubmit = () => {
    const { history } = this.props
    console.log(history)
  }

  render() {
    console.log('here')
    return (
      <div>
           <button onClick={this.handleSubmit}>Click me</button>
           <img src={path} width="400" height="400" alt="logo"/>
      </div>
    )
  }
}

export default withRouter(DashboardContainer)

My image path

0 个答案:

没有答案