vue v-for 使用问题整理小结
今天使用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>
通过变量中转一下,放到另一个临时变量中,如果有嵌套引用属性的话,大家记得通过js操作放到一个临时变量中,不然就会报错哟。
总结
以上所述是小编给大家介绍的vue v-for 使用问题整理小结,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
相关文章
vue转electron项目及解决使用fs报错:Module not found: Error: Can&apo
这篇文章主要给大家介绍了关于vue转electron项目及解决使用fs报错:Module not found: Error: Can‘t resolve ‘fs‘ in的相关资料,文中通过图文以及实例代码介绍的非常详细,需要的朋友可以参考下2022-11-11
Vue+ElementUI 封装简易PaginationSelect组件的详细步骤
这篇文章主要介绍了Vue+ElementUI 封装简易PaginationSelect组件,这里简单介绍封装的一个Pagination-Select组件几个步骤,结合示例代码给大家介绍的非常详细,需要的朋友可以参考下2022-08-08


最新评论