1

My App.vue has a V-for to create a Card Component, this Card receives the data through a Prop. Everything works fine except for the image.

In my App.vue

<DevJobCard :Job="item" v-for="item in filterSearch" v-bind:key="item.id"/>

The urls that my json provides

"logo": "./assets/logos/scoot.svg",

At the moment the only solution I have found is to put the images in the static folder and use this code so that you can at least see it in production. Help me please :( I haven't made any progress in 2 days

<img v-on="check" :src="'/static' + Job.logo.substring(1)" alt="">

I would like to know how to make it work if they are in assets or in static

2 Answers 2

2

If you want to load them by webpack you can simply use :src="require('path/to/file')". Try this code:

<img v-on="check" :src="require('/static' + Job.logo.substring(1))" alt="">
Sign up to request clarification or add additional context in comments.

1 Comment

I used your code adding "../" until reaching the path ": src =" require ('../../../ static' + Job.logo.substring (1)) "" Do you know if there is a way to reference the root path? so not full of "../", although it really is not a problem. Thank you very much, i was stuck for 2 days🤣
0

Your project is built, and image paths in the build can change after the build process.

You can try using the require() function. It works at build time:

// v-for="item in yourObject"
<img :src="require('./assets/logos/' + item.logo)" />

This way, webpack will know it needs to change the path to post-build one.

You may want to check this question out: https://stackoverflow.com/a/57350255/1722529

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.