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

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

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

今天使用v-for指令的時候遇到一個錯誤

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

頁面使用代碼

     <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>

報錯原因:

  我猜測使用了嵌套屬性的原因,在頁面中無法解析出具體屬性值,這個原因是我嘗試出來的,但是不知道深層次的原因了,有知道的希望評論下。

解決方案:

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

 <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>

通過變量中轉(zhuǎn)一下,放到另一個臨時變量中,如果有嵌套引用屬性的話,大家記得通過js操作放到一個臨時變量中,不然就會報錯喲。

總結(jié)

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

相關(guān)文章

最新評論