Hi, I recently discovered interesting challenge when implementing own user-profile-UI.
I use meteor-useraccounts/core and have an Vue component allowing the user to update his data. I use vue-meteor-tracker for the reactivity.
I was basically struggling with the necessity of having an input field updated by the tracked AND the user interaction. First I wanted to use a computed properties for values like profile.name
<template>
...
<input type="text" v-model="name" >
...
</template>
<script>
...
export default {
name: 'UserProfile',
data() {
updatedName: ''
},
computed: {
name: {
// getter
get: function () {
return this.userData && this.userData.profile && this.userData.profile.name ?
this.userData.profile.name : '';
},
// setter
set: function (updatedName) {
this.updatedName = updatedName;
}
},
meteor: {
$subscribe: {
'user-data': [],
},
userData(){
return Meteor.user();
}
},
}
</script>
There were several issues with that. updatedName
is empty, till there is at least some interaction on the related input. And for some reason the first interaction on the input (e.g. deleting a letter) did’n no change the input value.
I ended up by using a watcher
watch: {
userData (newUserData, oldUserData, ) {
this.name = newUserData && newUserData.profile && newUserData.profile.name ?
newUserData.profile.name : '';
},
},
which works fine, but it does feel like I am not using Vues data reactivity the right way. Has anyone a better solution ?