the nuxt framework uses asyncData, and needs to be re-npm run dev every time it changes. Otherwise, the error will be reported, and the code and error will be as follows
asyncData({ params }) {
let getNews = axios.getNews({ limit: 2 })
let getBannerPic = axios.getBannerPic()
let promise = Promise.all([getNews, getBannerPic])
return promise.then(res => {
let banners = []
let bannersData = res[1].data.data
for (let i = 0; i < bannersData.length; iPP) {
banners.push(bannersData[i]["mobile_img"]["url"])
}
console.log(banners)
return {
news: res[0].data,
banners: banners
}
})
}
error
Cannot read property "length" of undefined 19:37:13
at promise.then.res (pages_index.js:790:39)
at process._tickCallback (internal/process/next_tick.js:68:7)
but it is normal to execute npm run dev every time. When you change something else, it will be compiled automatically, and an error will be reported here
.