[Vuejs]-Vue & Vuex splice — cannot read property of null. Without splice content renders fine

1👍

The error message indicates that in this code:

computed: {
  experts () {
    return this.$store.getters.experts.slice(0,3);
  },
},

The experts Vuex getter is null. You need to ensure that the getter returns a non-null value at the time when the component is being rendered. Perhaps you didn’t initialize some data properly initially? Alternatively you can write defensive code which handles the case when experts is null so you don’t trigger the error.

You didn’t provide your code for the experts Vuex getter, so I can’t give you any further help.

0👍

Ok, so figured that I had experts: null in my state, but when I change it to experts:[] the error disappears but then still the content doesn’t render at all now.

why doesn’t the content show up once loaded? I thought computed with async would render once loaded!??!

Leave a comment