- 在
post index x
组件内使用了post list
组件,并在其中再次嵌套了post list
。 - 数据通过属性传递给组件。
post list
组件需要用到API HTTP客户端(apiHttpClient
)从app service
获取数据。- 该组件有一个创建生命周期(
create it
),创建后执行credit
函数。 - 在
credit
函数中,使用apiHttpClient
的GET请求获取数据,然后将结果存储在组件的post
数据中。 post list item
组件使用v-for
循环显示post
列表数据。- 每个列表项 (
post
) 绑定到post list item
组件的item
属性和key
属性(值为post.id
)。 post list item
组件声明支持item
属性,类型为object
。- 组件模板绑定输出
item
属性中的title
和item.user
的name
。 - 如果获取数据有误,浏览器的控制台会显示
cannot read property 'get' of undefined
。 - 错误是由于
apiHttpClient
的导入语法写错,应该使用大括号正确导入。 - 修正后,浏览器显示从服务器获取到的内容列表数据。