Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 使用webpack和url加载程序在React中加载内联图像_Css_Reactjs_Webpack_Webpack File Loader - Fatal编程技术网

Css 使用webpack和url加载程序在React中加载内联图像

Css 使用webpack和url加载程序在React中加载内联图像,css,reactjs,webpack,webpack-file-loader,Css,Reactjs,Webpack,Webpack File Loader,我需要使用内联样式并传入图像文件的url。我是这样做的: let url = `url(${this.state.logo})` var cardStyle = { backgroundImage: url, backgroundSize: '200px 50px', backgroundRepeat: 'no-repeat' } 然后在div中使用它,如下所示: <div class

我需要使用内联样式并传入图像文件的url。我是这样做的:

let url = `url(${this.state.logo})`
        var cardStyle = {
            backgroundImage: url,
            backgroundSize: '200px 50px',
            backgroundRepeat: 'no-repeat'
        }
然后在div中使用它,如下所示:

<div className='work-card' style={cardStyle}></div>

谢谢你的帮助

要解决您的问题,请更新
url加载程序
配置到:

{
  test: /\.(gif|png|jpg|svg)(\?.*$|$)/,
  use: [
    {
      loader: 'url-loader',
      options: {
        limit: 8192,
        name: '[name].[ext]',
        publicPath: 'images/'
      },
    },
  ],
},
{
  test: /\.(gif|png|jpg|svg)(\?.*$|$)/,
  use: [
    {
      loader: 'url-loader',
      options: {
        limit: 8192,
        name: '[name].[ext]',
        publicPath: 'images/'
      },
    },
  ],
},