Nuxt报错type check failed forprop "news"Expected Array

使用Nuxt.js的时候 报错 type check failed for prop "news". Expected Array, got Function. found in。
但是重新npm run dev 有没有任何问题,但是每次有一点改动 浏览器就会报这个错误。但是终端又是正常的。

组件
<template>
  <div class="leo-news">
    <div class="icon"/>
    <div class="news-list">
      <p 
        v-for="(item, index) in news" 
        :key="index"><a>{{ item.title }}</a></p>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    news: {
      type: Array,
      default: () => Array
    }
  },
  data() {
    return {}
  },
  created() {}
}
</script>
page
<style lang="scss">
.leo-news {
  height: 2rem;
  background: #fff;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  .icon {
    width: 1.2rem;
    height: 1.5rem;
    background: blue;
    float: left;
  }
  .news-list {
    width: 10rem;
    font-size: 0.4rem;
    float: left;
    padding-left: 0.333333rem;
    p {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    p:nth-child(2) {
      margin-top: 0.4rem;
    }
  }
}
</style>

<template>
  <div class="content">
    <section>
      <m-banner/>
      <m-LeoNews :news="news"/>
    </section>
    <section class="container">
      <m-vedio/>
    </section> 
    <section class="container">
      <m-huoke/>
    </section>
  </div> 
</template>
<script>
import axios from '~/fetch/fetch.js'
import Banner from '~/components/banner.vue'
import VedioCase from '~/components/vedioCase.vue'
import LeoNews from '~/components/leoNews.vue'
import Huoke from '~/components/huoke/huoke.vue'
export default {
  components: {
    'm-banner': Banner,
    'm-vedio': VedioCase,
    'm-LeoNews': LeoNews,
    'm-huoke': Huoke
  },
  data() {
    return {
      news: []
    }
  },
  created() {},
  asyncData({ params }) {
    //轮播图
    //新闻
    return axios.getNews({ limit: 2 }).then(res => {
      return { news: res.data }
    })
  }
}
</script>
<style lang="scss">
</style>
阅读 2.1k
2 个回答
default: () => Array

这返回值不是数组吧

news: {
  type: Array,
  default: () => Array
}

这里default不是应该直接给默认值吗??而且你这个表达不是有问题??、

news: {
  type: Array,
  default: [] /* 直接这样给不是好点?? */
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题