Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!