Stackedit/src/components/UserImage.vue

40 lines
832 B
Vue
Raw Normal View History

2017-10-02 00:34:48 +00:00
<template>
<div class="user-image" :style="{backgroundImage: url}">
2017-10-02 00:34:48 +00:00
</div>
</template>
<script>
2017-11-15 08:12:56 +00:00
import userSvc from '../services/userSvc';
2018-09-19 08:59:22 +00:00
import store from '../store';
2017-10-02 00:34:48 +00:00
export default {
props: ['userId'],
computed: {
sanitizedUserId() {
return userSvc.sanitizeUserId(this.userId);
},
2017-10-02 00:34:48 +00:00
url() {
const userInfo = store.state.userInfo.itemsById[this.sanitizedUserId];
2017-11-15 08:12:56 +00:00
return userInfo && userInfo.imageUrl && `url('${userInfo.imageUrl}')`;
2017-10-02 00:34:48 +00:00
},
},
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-10-02 00:34:48 +00:00
};
</script>
<style lang="scss">
.user-image {
width: 100%;
height: 100%;
2017-11-26 20:58:24 +00:00
background-color: #fff;
2017-10-02 00:34:48 +00:00
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
</style>