Stackedit/src/components/UserName.vue

28 lines
587 B
Vue
Raw Normal View History

2017-11-15 08:12:56 +00:00
<template>
<span class="user-name">{{name}}</span>
</template>
<script>
import userSvc from '../services/userSvc';
2018-09-19 08:59:22 +00:00
import store from '../store';
2017-11-15 08:12:56 +00:00
export default {
props: ['userId'],
computed: {
sanitizedUserId() {
return userSvc.sanitizeUserId(this.userId);
},
2017-11-15 08:12:56 +00:00
name() {
const userInfo = store.state.userInfo.itemsById[this.sanitizedUserId];
2017-11-15 08:12:56 +00:00
return userInfo ? userInfo.name : 'Someone';
},
},
2018-09-19 08:59:22 +00:00
watch: {
sanitizedUserId: {
handler: sanitizedUserId => userSvc.addUserId(sanitizedUserId),
2018-09-19 08:59:22 +00:00
immediate: true,
},
},
2017-11-15 08:12:56 +00:00
};
</script>