Nuxt.js: How to link img src to a rendered list

Created on 25 Mar 2017  路  7Comments  路  Source: nuxt/nuxt.js

Im trying to render a list with an image where the name of the images come from an array of objects.

error

How do I properly link it?

Thank you in advance.

This question is available on Nuxt.js community (#c389)
question

Most helpful comment

Note for future googlers - another way to solve this is to use require. E.g.
const imageUrl = require('~/assets/img/yourimage.png')

Then dynamically using that url in js.

All 7 comments

vue file will pre work with vue loader
when vue load seen you vue file that don't know what is '~assets/img/' + item.logo
because item.logo when compile is undefined .

so , if you want use a variable with you image , you need move your image to static folder
that will copy to dist . ( even you never used )

if item.logo = 'logo.png'
put the logo.png to static/img/logo.png
and in your vue file modify to
<img :src="`img/${item.logo}`"/>

that your logo should show on screen .

Hi @tenjojeremy,
Like @ausir0726 said for dynamic path, you can't use webpack assets, you need to use static assets and place your images in the static folder.

Thank you both for the solution, @ausir0726 @alexchopin

Cheers.

Note for future googlers - another way to solve this is to use require. E.g.
const imageUrl = require('~/assets/img/yourimage.png')

Then dynamically using that url in js.

for Googlers, I had success with:

:style="{ backgroundImage: 'url(' + require(@/assets/img/${page.image}) + ')' }"

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

For all people looking for the solution, I've written a blog post about that topic :relaxed:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

uptownhr picture uptownhr  路  3Comments

bimohxh picture bimohxh  路  3Comments

vadimsg picture vadimsg  路  3Comments

vadimsg picture vadimsg  路  3Comments

danieloprado picture danieloprado  路  3Comments