抱歉,如果这真的很明显,但我 \xe2\x80\x99m 是 Vue 新手,需要一些帮助。
\n\n我\xe2\x80\x99m 从我的商店中获取一组数据(帖子),并尝试控制台仅记录数组中的一个对象,但它\xe2\x80\x99s 每次都显示未定义。如果我控制台记录整个数组,它会返回正常。
\n\nI\xe2\x80\x99m 猜测这与创建的钩子中的 console.log 之前未加载数据有关?我\xe2\x80\x99已经尝试了我能做的一切,但它\xe2\x80\x99让我发疯。任何帮助表示赞赏(下面的简化代码)。
\n\n<script>\n export default {\n components: {},\n\n computed: {\n posts() {\n return this.$store.state.posts;\n }\n },\n created() {\n this.$store.dispatch("getPosts");\n console.log(this.posts[0])\n },\n };\n </script>\n\n\n//Store code Below\n\nexport const state = () => ({\n posts: [],\n })\n\n export const mutations = {\n updatePosts: (state, posts) => {\n state.posts = posts\n }\n }\n\n export const actions = {\n async getPosts({\n state,\n commit,\n dispatch\n }) {\n if (state.posts.length) return\n\n try {\n let …Run Code Online (Sandbox Code Playgroud)