[Vuejs]-Vuejs computed properties that depend on other, asynchronous, computed properties

0๐Ÿ‘

I would suggest that you need to create getters for your apple sauce.. er.. source.. er.. src ๐Ÿ™‚

<template>
    <div class="apples">
        <div id="mast" class="f3 b bb b--black-10">
            <h2 class="ttc">Apple's List</h2>
        </div>
        <div id="content">
            <li v-for="apple in apples" class="list-item">
                <avatar :src="getAvatar(apple, 256)" :size="50" :appletype="apple.type"></avatar>
            </li>
        </div>
    </div>
</template>

<script>
    import Avatar from './Avatar.vue';
    import Apples from '@/api/apples';

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

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

๐Ÿ‘คgeoidesic

Leave a comment