Nuxt.jsのCannot read property 'fields' of undefined"を解決したい。
nuxt.js、contentful apiを使って簡単なブログの様なものを作成しようとしています。
ローカル環境でプロジェクトを起動させようとした際に、ターミナルでは正常に作動した様に見えるのですが、実際にローカルで開いてみるとエラーが発生します。
Cannot read property 'fields' of undefined"というのがいくら調べても曖昧な回答しか得られず、何がどうダメなのかが分からないので、教えて頂けるととてもありがたいです。
発生している問題・エラーメッセージ
######ターミナル上で表示されたエラー
ERROR [Vue warn]: Error in render: "TypeError: Cannot read property 'fields' of undefined"
found in
---> <Pages/index.vue> at pages/index.vue
<Nuxt> <Layouts/default.vue> at layouts/default.vue <Root>
######ローカルのページで表示されるエラー(表示されている文を書き写したものになります。)
Cannot read property 'fields' of undefined
pages/index.js:146:60(しかし、pagesの下にindex.jsは無く、index.vueとReadme.mdがあるのみです)
pages/index.js
Missing stack frames
pages/index.vue:20:
pages/index.vueopen in editor
:key="i"
cols="12"
sm="6"
lg="4"
xl="3"
>
<v-card
max-width="400"
class="mx-auto"
>
<v-img
該当のソースコード
#####pages/index.vue
vue
1<template> 2 <v-container fluid> 3 <v-row 4 justify="center" 5 > 6 <v-col 7 cols="12" 8 sm="11" 9 md="10" 10 xl="8" 11 > 12 <v-row v-if="posts.length"> 13 <v-col 14 v-for="(post, i) in posts" 15 :key="i" 16 cols="12" 17 sm="6" 18 lg="4" 19 xl="3" 20 > 21 <v-card 22 max-width="400" 23 class="mx-auto" 24 > 25 <v-img 26 :src="post.fields.image.fields.file.url" 27 :alt="post.fields.image.fields.title" 28 :aspect-ratio="16/9" 29 max-height="200" 30 class="white--text" 31 > 32 <v-card-title class="align-end fill-height font-weight-bold"> 33 {{ post.fields.title }} 34 </v-card-title> 35 </v-img> 36 37 <v-card-text> 38 {{ post.fields.publishDate }} 39 </v-card-text> 40 <v-list-item three-line style="min-height: unset;"> 41 <v-list-item-subtitle> 42 {{ post.fields.body }} 43 </v-list-item-subtitle> 44 </v-list-item> 45 <v-card-actions> 46 <v-spacer /> 47 <v-btn 48 text 49 color="primary" 50 > 51 この記事をみる 52 </v-btn> 53 </v-card-actions> 54 </v-card> 55 </v-col> 56 </v-row> 57 <div v-else class="text-center"> 58 投稿された記事はありません。 59 </div> 60 </v-col> 61 </v-row> 62 </v-container> 63</template> 64<script> 65import client from '~/plugins/contentful' 66 67export default { 68 async asyncData ({ env }) { 69 let posts = [] 70 await client.getEntries({ 71 content_type: env.CTF_BLOG_POST_TYPE_ID, 72 order: '-fields.publishDate' 73 }).then(res => (posts = res.items)).catch() 74 return { posts } 75 } 76} 77</script> 78
試したこと
申し訳ないのですが、Cannot read property 'fields' of undefinedやその周辺のキーワードで検索しただけです。3時間ほどかけて検索や関連のエラーの対策なども検索してみましたが、はっきりとしたワードや解決策が得られず、今回質問させていただいています。
どうかよろしくお願いします。
補足情報(FW/ツールのバージョンなど)
使っているもの
Macbook2017
Nuxt.js v2.11.0
yarn 1.21.0
contentful api

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/26 12:25
2020/01/26 13:28
2020/01/26 15:31
2020/01/31 13:58