Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
How to load locally stored images conditionally in Vuejs?

<template>
  <div>
    <div v-if="item">
      <h1>Price: {{ item.email }}</h1>
      <v-if item.email=="john@gmail.com">
        <img :src="../"/>
      </v-if>
    </div>
  </div>
</template>

<script>
import { routerid } from "./routerid";
export default {
  name: "User",
  components: {},
  data() {
    return {
      item: [],
    };
  },
  mounted() {
    this.loadData();
  },
  computed: {
    routeId() {
      return this.$route.params.id;
    },
  },

  watch: {
    routeId() {
      console.log("Reload (route change)");
      this.loadData();
    },
  },

  methods: {
    loadData() {
      console.log("Reloading, ID", this.routeId);
      if (!this.routeId) return;
      routerid(this.$route.params.id).then((item) => {
        this.item = item.data;
      });
    },
  },
};
</script>

How to load locally stored images conditionally in Vuejs?

I have three images stored inside of my assets folder. as below.

enter image description here

Now in frontend i want to call them conditionally like for example (if ---> john@gmail.com show the john image stored inside of assets folder. Else no. Similarly for other images too. Like derk and Kate...

Do i need to write if else condition. To load the images based on email? Or any other way to do that?

Code:- https://codesandbox.io/s/combined-logic-api-forked-nzzzwc?file=/src/components/User.vue

api response:- https://fakestoreapi.com/users/1

{"address":{"geolocation":{"lat":"-37.3159","long":"81.1496"},"city":"kilcoole","street":"new road","number":7682,"zipcode":"12926-3874"},"id":1,"email":"john@gmail.com","username":"johnd","password":"m38rmF$","name":{"firstname":"john","lastname":"doe"},"phone":"1-570-236-7033","__v":0}

Note:- email will be different for each id.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

First. I think you should provide image link on your API Response (so you should add image link column on your database table). Or if you insist, based on your case, you can use this:

<div v-if="item">
  <h1>Price: {{ item.email }}</h1>
  <img :src="getPic(item.email)"/>
</div>

and in your method:

getPic(src) {
  return "@/assets/" + src.substring(0, src.lastIndexOf("@")) + ".png"
}

But I still really think you should store iamge link in your database

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda