Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Img element from Vue.js component is not rendered into Laravel production environment

I am compiling an img element for production with npm run prod from resources/images dir. The compilation is done with webpack.mix.js:

const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css').vue();

Bottom of welcome.blade.php:

<body id="body">
  <div id="app">
    <app></app>
  </div>
</body>
<script src="{{ mix('js/app.js') }}"></script>
</html>

The img element is inside a vue component:

  <img :src="require('../images/portrait.png')" id="portrait" alt="">

and gets compiled to public/images dir:

enter image description here

As you can see portrait.png is compiled into public/images. But as soon as I try to run the app with php artisan serve the image is not displayed in the browser. It is the only image not displayed. The browser console shows:

Failed to load resource: the server responded with a status of 404 (Not Found)

on initial page load and:

GET http://127.0.0.1:8000/require(%60../images/portrait.png%60) 404 (Not Found)

on page refresh.

According to this img src thread on github require should work for img elements but it doesn't. Any workaround?

specs:

OS: Windows 10
Vue.js: 4.5.13
Laravel: 8.55.0
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There seems to be an issue with resolving the image as module. Could you try adding .default to the require statement?, e.g.

<img :src="require('../images/portrait.png').default" id="portrait" alt="">

Reference: https://github.com/JeffreyWay/laravel-mix/issues/2756

about 4 years ago · Juan Pablo Isaza Relatório

0

Can you just use <img src="images/portrait.png" id="portrait" alt=""> ?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda