javascript - 未附加 vue 注释
问题描述
在我刷新页面之前,我的 Vue 代码不起作用。评论的回复成功进入数据库,但直到我刷新页面或添加评论然后刷新然后添加回复才显示在浏览器中。
评论.vue
我的方法
appendReply(comment,reply){
_.find(this.comments, { id: comment.id }).children.push(reply)
},
已安装
bus.$on('comment:replied', ({ comment, reply }) => {
this.appendReply(comment, reply)
this.scrollToComment(reply)
})
我在控制台中收到此错误
[Vue 警告]:“comment:replied”的事件处理程序出错:“TypeError:无法读取未定义的属性‘push’”
解决方案
由于我知道您从哪里获得此代码以及流程是什么,因此我将为您提供问题的解决方案。
亚历克斯在解释appendReply
方法时一直whenLoaded
在CommentResource
回复(孩子们)。
要解决此问题,您需要转到后端提供的 Commentresource 类并将回复(子)属性设置为此代码:
'replies' => CommentResource::collection($this->replies)
或者在你的情况下
'children' => CommentResource::collection($this->children)
推荐阅读
- node.js - Discord.JS 从消息中获取所有附件
- html - 如何迭代 Map 值的值
- python - 如何在 PDB 中输入 Python 代码而不将其解释为命令?
- java - 为什么我不能访问类变量的值,因为类变量是在创建对象时初始化的
- database - PostgreSQL vs MongoDB 在 Django 应用程序中执行 python 函数
- python - 如何连续循环我的比特币价格检查器?
- javascript - REACT NATIVE:如何获取 API 数据 (JSON) 并插入到 Flatlist、API
- verilog - 将 4 位计数器的输出连接到 Hex 到 7-Seg 解码器并创建测试台
- c# - 如何使用 .Net Core 验证 KeyCloak 提供的 JWT?
- regex - 如何在不拆分 McDonald 的情况下将 camelCase 与 Regex 拆分?