【发布时间】:2020-04-02 04:15:08
【问题描述】:
我有三个 vue.js 文件。其中父文件(parent.vue)包含profile:[]的数据
使用props方法将配置文件的数据发送到子文件(child.vue)。
child.vue 也有它自己的子文件 (grandchild.vue),它通过使用 props 与 profile 数据一起传递。
孙子将向 API 发送 put 请求以更改配置文件中的某些数据。
我的问题是。我如何确保道具会在配置文件数据中所做的每一次更改时更新。
信息:(parent.vue = 主文件,child.vue = 抽屉(来自 ant design),grandchild = 弹出框)
在孙子成功向 API 发送 put 请求后,我需要 child.vue 更新配置文件数据。
有什么方法或参考链接,所以我可以在来自grandchild.vue 的 put 请求后更新道具我尝试了 watch 方法,但问题是用户需要先关闭抽屉(child.vue)然后重新打开抽屉来更新道具。有什么方法可以在不关闭抽屉的情况下更新道具?
代码示例:
父.vue:
// structure
<child.vue
:profile="profile"
/>
child.vue 和 grandchild.vue :
//script
props : [profile],
profile 可以用作 html 中的 {{profile.subsdata}} 或 this.profile.subsdata javascript
【问题讨论】:
-
适当使用
:key绑定可能会有所帮助,但如果您没有显示任何代码,则很难提供建议
标签: vue.js