[Vuejs]-Getting an error TypeError: Cannot read properties of undefined (reading 'state') in vuejs while using Vuex

0👍

mapState is a helper that simplifies creating a computed property that reflects the value of a given state

You can access your data like below:

<template>
  <div>
    <h4>Todo list</h4>
    <todo
      v-for="(task, index) in todos" 
      :key="index"
      :todo="todo"
    ></todo>
  </div>
</template>


import { mapState } from 'vuex'
export default {
  data: {},

  computed: {
   ...mapState({
    todos: state => state.todos
   })
  }
}

Leave a comment