You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a meteor property relies on any props or other component data or computed properties, it causes an error when used with $lazy: true. It seems that the function is being called within the beforeCreate hook at which point the other data doesn't exist yet.
e.g:
props: ['userId'],meteor: {$lazy: true,avatar(){console.log(this.userId);// [Vue warn]: Error in beforeCreate hook: "TypeError: Cannot read property 'userId' of undefined"constuser=Meteor.users.findOne({_id: this.userId},{fields: {"profile.avatar": 1}});returnMeteor.absoluteURL('avatars/'+user.profile.avatar);}}
My work-around is to do this instead:
props: ['userId'],computed: {avatar(){()=>{returnthis.$autorun(()=>{console.log(this.userId);// no problemconstuser=Meteor.users.findOne({_id: this.userId},{fields: {"profile.avatar": 1}});returnMeteor.absoluteURL('avatars/'+user.profile.avatar);})}}
The text was updated successfully, but these errors were encountered:
If a meteor property relies on any props or other component data or computed properties, it causes an error when used with
$lazy: true
. It seems that the function is being called within thebeforeCreate
hook at which point the other data doesn't exist yet.e.g:
My work-around is to do this instead:
The text was updated successfully, but these errors were encountered: