我今天在使用v-for指令时遇到了一个错误
[Vue warn]: render :中的错误“TypeError:无法读取未定义的属性“children”
页面使用代码
modelList中的模板v-for='(c,I)。course . children ' div : key=' I ' class=' course-block ' course struct : process=' is buy ' : course=' c '/div/templatescripteexport default { methods : { async GetList(id){ const RES=wait GetChaplistByProductid(id);if(RES . data){ this . model list=RES . data;} } } }/脚本错误原因:
我猜是使用嵌套属性的原因,具体属性值在页面中无法解析。我试过这个原因,但是不知道更深层次的原因,所以希望知道了再评论。
解决方案:
既然知道了原因,就可以这样解决了。
模板v-for='(c,I)in cls ' div : key=' I ' class=' course-block ' course struct : process=' is buy ' : course=' c '/div/模板脚本导出默认值{ methods : { async getList(id){ const RES=await getchapterslistbyProductid(id);if(RES . data){ this . model list=RES . data;varco=this . model list . course this . cls=co . children } } }脚本通过变量传递,并放入另一个临时变量中。如果有嵌套的引用属性,应该记得通过js操作将它们放入临时变量中,否则会报错。
摘要
以上是边肖介绍的vue v-for的使用总结,希望对大家有所帮助。如果你有任何问题,请给我留言,边肖会及时回复你的!