Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda