前提・実現したいこと
Railsで記事を作成して、その情報をNuxtで表示させるサイトを作っています。
発生している問題・エラーメッセージ
ローカル環境では表示されますが、本番環境になるとAPIの読み込みがされず、ブラウザにAPIの情報が表示されません。
TypeError: Cannot read property 'title' of undefined```
該当のソースコード
_id.vue
1<div class="contents-header"> 2 <h1>{{posts.title}}</h1> 3 </div> 4 5 export default { 6 7head(){ 8 return{ 9 title: this.posts.title, 10 meta:[ 11 { hid: 'title', name: 'title', content: this.posts.title } 12} 13 14async asyncData({app,params,error}) { 15 const {id} = params; 16 const response = await axios.get(`https://hogehoge.com/api/v1/posts/${id}`) 17 .catch(err=> { 18 error({ 19 statusCode: err.response.status, 20 message: err.response.data.message, 21 }); 22 return err.response; 23 }); 24 const posts = JSON.parse(response.data) 25 return {posts}; 26 }, 27}
試したこと
APIの呼び出しをmounted内に書いたら表示はされましたが、代わりにOGPが表示されなくなりました...
拙い説明ですいません。どうかよろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/30 09:59
2020/01/31 03:26 編集