0👍
✅
There are a few things that you have to observe here:
- Vue doesn’t watch nested properties. To make it watch, use
$set
instead - When you call
this.resetCurrentName
inupdateName
, you are resetting the changes made in vue instance. Since, mounted isn’t called on prop updates, it is causing the oldthis.name
to be used instead of the new one. You can check the same inconsole.log
s
Here is the link to working example: https://codesandbox.io/s/tender-payne-7ydb6
0👍
Here is the link of the updated sandbox https://codesandbox.io/s/pensive-ives-jex2e
update() {
this.$emit("update", this.currentName);
this.resetCurrentName();
}
Don’t reset the name on updating.
Source:stackexchange.com