[Vuejs]-Vuex mapped state always undefined in component

0๐Ÿ‘

  1. your data section looks incorrect. It should look like this:
data() {
    return {
      defaultSelected: this.items[0]
    }
 },

  1. In mapState you should indicate state props (and their module name if they are not from the root state). I assume that carDetail.js is a store module.
computed () {
  ...mapState({
     id: state => state.cartDetail.id,
     items: state => state.cartDetail.items
  }),

  setDefaultSelected () {
   return this.items[0];
  },
 },

Leave a comment