I have this simplified avatar component:
<template>
<img :src="src">
</template>
<script>
export default {
name: 'Avatar',
props: {
src: {
type: String,
default: '/static/avatar-default.png'
}
}
}
</script>
Let's say I fetch some user data from my API and it contains no avatar URL. In such case I want this component to use the default value but it only seems to work when passing undefined
to it, but undefined
is not valid in JSON so I cannot return that from the API response.
Is there a way to realize what I want by passing in null
or is there a better way to handle this?