3

I am having trouble displaying images in my Vue CLI project.

Here is what I have going on. This vue file accesses a json file with a few references to the individual Eyewear objects, all that works. I have references to the image I am trying to access in the json file. And with the current code, I can see the correct image reference in the browser, but it does not load the image. Is it something to do with webpack or another loader needing to load the image file?

    <template>
  <div>
    <h1 id='callout'>Select Your Eyewear</h1> 
    <div id='item' v-for='item in items' :key=item.id>
      <img :src='`..${item.images.frontal}`' alt='eyeware' />
      <ul id='itemLIist'>     
        <li >
          {{ item.brand }}
        </li>
        <li>
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import items from "../assets/eyewear.json";

export default {
  name: "ItemList",
  data: function() {
    return {
      items: items.eyewear
    };
  }
};
</script>

<style scoped>
</style>

enter image description here

John Bull
  • 103
  • 3
  • 12
  • I'm in a similar boat. I externalized a component into html, and typescript and no matter what ../../../, ../../, ../ or ./ or @/ or ~@, or ~ works. Think its something with Webpack now so more research needed. – Mark Apr 13 '19 at 14:40
  • Yeah, I think so, it was a while ago and I don't think I ended up getting it in Vue. Since it was a demo, I ended up switching to create react app. But if I ever circle back around and get this I will update the post. – John Bull Apr 16 '19 at 22:18
  • 2
    Ok my workaround was to do this - ```CompanyName``` – Mark Apr 17 '19 at 21:32

1 Answers1

1

I don't know this works for you or not. But in my case providing the full path of the image works for me. in your screenshot reference starting from "../assets" instead of that try something "src/assets" (Full path with out dots)

and for make this simple, first just try to hard code full path src to a image tag and see whether it's working or not.

and let me know if this works for you. =)

margherita pizza
  • 6,623
  • 23
  • 84
  • 152
  • Thanks, while I have tried the full path in my dynamic render, I haven't tried to hardcode it for troubleshooting purposes, I am going to try that now. – John Bull Sep 27 '18 at 03:50
  • No that doesn't seem to load, even when hardcoded from the source. All image files are in assets/images. – John Bull Sep 27 '18 at 04:31
  • then It may possible some webpack configuration thing has to do and also at one time jpg and JPEG matters for me. I know it's wired but it happens to me. Try JPEG and see. also this may help you https://stackoverflow.com/questions/49290208/vue-js-dynamic-image-paths-not-loading – margherita pizza Sep 27 '18 at 04:40
  • I was able to get it to work, one thing that was tripping me up was in the object key I was pulling the dynamic path the image, was a "-" and it did not like that. Went down the rabbit hole on that. Anyone that finds this the relative path in the code does work. – John Bull Sep 28 '18 at 04:10