いつもお世話になります。
nuxt.jsでWebページの作成練習しています。
axiosでJSONを取得しv-forでリスト表示を行いたいと思っていますが、下記のようにエラーが出てしまいます。
エラーメッセージ
Property or method "lists" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
javascript
1<template> 2 <div> 3 <section class="hero is-primary is-bold"> 4 <div class="hero-body"> 5 <div class="container"> 6 <h1 class="title"> 7 nuxt v-for 8 </h1> 9 <h2 class="subtitle"> 10 nuxt v-for 11 </h2> 12 </div> 13 </div> 14 </section> 15 <div class="container is-fluid"> 16 <div> 17 <ul> 18 <li v-for="list in lists" v-bind:key="list.id"> 19 {{ list.name }}{{ list.id }} 20 </li> 21 </ul> 22 </div> 23 </div> 24 </div> 25</template> 26<script> 27 import axios from 'axios' 28 export default { 29 data() { 30 list : [] 31 }, 32 created: function () { 33 axios.get('1.json').then(function (response) { 34 this.list = response.data 35 }.bind(this)).catch(function (e) { 36 console.error(e) 37 }) 38 } 39 } 40</script> 41
お忙しいところ恐れ入りますがよろしくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/25 13:19 編集
2018/08/25 13:31
2018/08/25 13:33