<template>
<img :src="user.avatar_thumbnail">
<a :href="user.profile.link"/>
</template>
<script>
export default {
data: function () {
user: {}
},
mounted: function() {
let vm = this;
axios.get('user/profile/<id>').then((response) => {
vm.user = response.data.user
});
}
}
</script>
In cases where the server does not send the 'avatar_thumbnail' field in the user object, the page will not render properly.
I have been using ternary expressions to handle this scenario, but it is not applicable everywhere.
<img :src="user.avatar_thumbnail ? user.avatar_thumbnail : '' ">
Is there a Vue.js tool available to address this issue?
Furthermore, if the server sends objects with nested fields like 'user.profile.avatar_thumbnail', I prefer not to use nested ternary expressions (please do not suggest computed methods - I would consider them if no other solution exists).