Skip to content Skip to sidebar Skip to footer

Vuejs Computed Properties That Depend On Other, Asynchronous, Computed Properties

In my Vuejs app I need to pass two computed properties to a component called avatar: an image surce and a string. The problem is that not all items have a picture, and when they do

Solution 1:

I would suggest that you need to create getters for your apple sauce.. er.. source.. er.. src :)

<template><divclass="apples"><divid="mast"class="f3 b bb b--black-10"><h2class="ttc">Apple's List</h2></div><divid="content"><liv-for="apple in apples"class="list-item"><avatar:src="getAvatar(apple, 256)":size="50":appletype="apple.type"></avatar></li></div></div></template><script>importAvatarfrom'./Avatar.vue';
    importApplesfrom'@/api/apples';

    exportdefault {
        name: 'apples',
        methods: {
            getAvatar: function(obj, id) {
                   return obj.album_id.apples[ id ] | ''
            }
        },
        asyncComputed: {
            apples: {
                asyncget() {
                    const apples = awaitApples.getAll();
                    return apples.data;
                },
                default: []
            }
        },
        components: {
            Avatar
        }
    };
</script>

This allows you to create a graceful fallback with whatever arguments and implementation you choose.

Post a Comment for "Vuejs Computed Properties That Depend On Other, Asynchronous, Computed Properties"