1

I have this vue function. That should return the img srs, dynamically. For some reasons, it is not reading the string as a local file. Image is not showing.

script 

 showSuccessPercentage(recieved) {
      if (typeof recieved === "object" && recieved != null) {

        if(recieved["successRunsPercentage"] > 50) {
          return "'../assets/img/rainy.png'"
        }
              } 
      else return "N/A";
      
    },

HTML

<img class= "w-10" :src="showSuccessPercentage(currentView.worstReport) " alt="Organization Icon" />

looks simple. Not sure why it's giving me a hard time.

1 Answer 1

1

You need to use require method to get the local image render in Vue.app.

showSuccessPercentage(recieved) {
    if (typeof recieved === "object" && recieved != null) {

      if (recieved["successRunsPercentage"] > 50) {
        return require('../assets/img/rainy.png')
      }
    } 
    else return "N/A";
  },
Sign up to request clarification or add additional context in comments.

2 Comments

I tried, but no. It's not working. Any other guide?
Sorry for that. Yes it worked with required. Not sure why it didn't the first time....Really thank you !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.