[Vuejs]-How can I ensure my not yet fetched data doesn't break my site

0👍

Here’s an opinionated answer: use get from lodash.

npm i lodash

Then you can write something like this:

import get from 'lodash/get';

export default {
  computed: {
    isLiked() {
      const cardId = get(this.$store, 'state.loadedCards[0].id');
      const postIds = get(this.$store, 'state.userInfoSub[0].liked_posts', []);
      return postIds.includes(cardId);
    },
  },
};

Leave a comment