0

I'm new to Vue and utilising a World Cup API to build a simple Laravel app. I have the following code:

<img src="http://www.countryflags.io/@{{ match.home_team.code | truncate(2) }}/flat/64.png">

Which should ideally output the following:

<img src="http://www.countryflags.io/FR/flat/64.png">

But instead I get an error because it's not parsing the @{{ }} block properly inside Laravel/Vue.

This is the truncate filter I'm trying to use incase that's important - https://www.npmjs.com/package/vue-truncate-filter

match.home_team.code should return FRA for France for example, but I only need FR

What is the best way for me to achieve what I'm after?

1 Answer 1

1

You could use template literals and do this:

<img :src="`http://www.countryflags.io/${match.home_team.code.substring(0, 2)}/flat/64.png`">

Might also work with a filter, but I'm not sure about that.

Sign up to request clarification or add additional context in comments.

3 Comments

Kinda works, but still get a bit of an error with the attempted output. http://www.countryflags.io/$%7Bmatch.home_team.code.substring(0,2)%7D/flat/64.png 404 (Not Found)
Did you add : to the :src?
YEah copied it exactly as above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.