欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue v-for 使用問(wèn)題整理小結(jié)

 更新時(shí)間:2019年08月04日 08:46:05   作者:大穩(wěn)·楊  
使用v-for指令的時(shí)候遇到一個(gè)錯(cuò)誤問(wèn)題,具體錯(cuò)誤代碼在文章給大家列出,對(duì)vue v-for使用問(wèn)題感興趣的朋友跟隨小編一起學(xué)習(xí)吧

今天使用v-for指令的時(shí)候遇到一個(gè)錯(cuò)誤

[Vue warn]: Error in render: "TypeError: Cannot read property 'children' of undefined"

頁(yè)面使用代碼

     <template v-for="(c,i) in modelList.Course.children">
       <div :key="i" class="course-block">
        <CourseStruct :process="isbuy" :course="c" />
       </div>
      </template>
<script>

export default {
    methods: {
      async getList(id) {
        const res = await GetChapterListByProductID(id);
        if (res.data) {
          this.modelList = res.data;
         }
      }
   }
}

</script>

報(bào)錯(cuò)原因:

  我猜測(cè)使用了嵌套屬性的原因,在頁(yè)面中無(wú)法解析出具體屬性值,這個(gè)原因是我嘗試出來(lái)的,但是不知道深層次的原因了,有知道的希望評(píng)論下。

解決方案:

  既然知道了原因,那么就好解決了,解決方法如下.

 <template v-for="(c,i) in cls">
       <div :key="i" class="course-block">
        <CourseStruct :process="isbuy" :course="c" />
       </div>
      </template>

      <script>

       export default {
        methods: {
           async getList(id) {
           const res = await GetChapterListByProductID(id);
           if (res.data) {
           this.modelList = res.data;
           var co = this.modelList.Course
           this.cls = co.children
           }
         }
        }
       }

      </script>

通過(guò)變量中轉(zhuǎn)一下,放到另一個(gè)臨時(shí)變量中,如果有嵌套引用屬性的話,大家記得通過(guò)js操作放到一個(gè)臨時(shí)變量中,不然就會(huì)報(bào)錯(cuò)喲。

總結(jié)

以上所述是小編給大家介紹的vue v-for 使用問(wèn)題整理小結(jié),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

相關(guān)文章

最新評(píng)論