0

For some reason the imageURL property is not working, even though the url is correct, with the v-bind:src attribute.

The template:

<div v-for="project in projects" :key="project.id">
    <section class="project-wrapper">

        <img :src="project.imageURL" alt="Project image"/> //THE PROBLEM

        <h1>{{ project.title }}</h1>
        <p>{{ project.about }}</p>
        <router-link :to="{ name: project.routeName }" class="type-two-link">ver projeto</router-link>

    </section>
</div>

The script:

data() {
    return {
      projects: [
        {
          id: this.projectId,
          title: "Minimalist Portfolio",
          about: "...",
          imageURL: "./minimalist-porfolio-desktop.png", //THE PROBLEM
          routeName: "Minimalist Portfolio",
        },
      ],
    };
  },

What am I doing wrong? Any help is welcome.

1 Answers1

2

I've tried to use 'required()' in the template, but it didn't worked. So, this is how I solved it:

data() {
    return {
      projects: [
        {
         "...",

          imageURL: require("../../assets/images/projects/minimalist-portfolio/minimalist-porfolio-desktop.png"),

          routeSlugName: "My Portfolio",
        },
      ],
    };
  },
,

You can learn more here: Static image src in Vue.js template