Currently I am querying a Firebase database for the current users username. I would like the value to display on the page inside the <template> area. Looked through the docs but still new to Vue.
Everything will output into the console correctly, I am just unsure of the next step to reference inside the <template> using moustache handles eg. {{ user.username }}
data() {
return {
userName: ''
}
},
methods: {
getName: function() {
var userId = firebase.auth().currentUser.uid;
return firebase.database().ref('users/' +
userId).on('value', function(snapshot) {
if (snapshot.val()) {
var obj = snapshot.val();
var userName = snapshot.val().username;
console.log('username:', userName)
}
});
}
}
Template
<template>
<span>{{ user.username }} (Output result of var userName here)</span>
</template>
{{ userName }}?userdata item. You haveuserName. You should probably set it in your.oncallback, taking care to havethisset properly.