Я строю проект для изучения Vuex . Я создаю массив объектов в моем store
примерно так:
Магазин Vuex:
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {
users: [
{ id: 1, name: 'John Doe', email: 'johndoe@gmail.com' },
{ id: 2, name: 'Jane Doe', email: 'janedoe@gmail.com' },
{ id: 3, name: 'Mark Greywood', email: 'markgreywood@gmail.com' },
]
},
mutations: {},
actions: {},
modules: {}
});
Теперь яm доступ к state
в компоненте с вычисляемым свойством, например:
Компонент:
<template>
<div class="home">
<h1>Hello from Home component</h1>
<!-- I do not loop through the users, nothing shows -->
<div v-for="user in users" :key="user.id">{{ user.name }} </div>
<!-- I get the users object in the DOM -->
<div>{{ getUsers }}</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
name: "Index",
computed: mapState({
getUsers: state => state.users
})
};
</script>
<style scoped lang="less">
</style>
Я не понимаючто я делаю не так