0

I'm currently build a little component with an image fallback, it should be implemented like this:

export default {
 name: "ChannelHeader",
 props: ['channel'],
 methods : {
 channelLogo(channel) {
 if(channel?.thumbnails?.high) return channel.thumbnails.high
 if(channel?.thumbnails?.medium) return channel.thumbnails.medium
 if(channel?.thumbnails?.default) return channel.thumbnails.default
 return "~@/assets/material_header_medium.jpg"
 }
 }
}

when all fails the channelLogo should been loaded from assets folder this works all fine beside that the URL is not redered.

the html for the logo is:

 <img uk-cover :src="channelLogo()" :alt="channel?.title+' Logo'">

And rendered:

<img uk-cover="" src="~@/assets/material_header_medium.jpg" alt="undefined Logo" data-v-5d87ed20="" class="uk-cover" style="height: 70px; width: 70px;">

In the same component i use this image as div background:

.channel-header{
 background-image: url("~@/assets/material_header_medium.jpg");
 min-height: 300px;
}

So how is the Syntax to give back those relative paths from a method?

asked Apr 15, 2021 at 15:19
1
  • 2
    You need tu use require() - return require("~@/assets/material_header_medium.jpg") Commented Apr 15, 2021 at 15:31

1 Answer 1

1

Like mentioned by Vucko it was needed to wrap the path into a required. but it will not work when using:

return require("~@/assets/material_header_medium.jpg")

i had to use:

return require("@/assets/material_header_medium.jpg")

As an alternative i have first importet the media and used it later:

import fallbackImage from '@/assets/material_header_medium.jpg'
...
return fallbackImage
answered Apr 15, 2021 at 18:29
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.