UserIdToUsername.vue 751 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <router-link
  3. v-if="$props.link && username !== 'unknown'"
  4. :to="{ path: `/u/${username}` }"
  5. :title="userId"
  6. >
  7. {{ username }}
  8. </router-link>
  9. <span :title="userId" v-else>
  10. {{ username }}
  11. </span>
  12. </template>
  13. <script>
  14. import { mapActions } from "vuex";
  15. export default {
  16. props: {
  17. userId: { type: String, default: "" },
  18. link: Boolean
  19. },
  20. data() {
  21. return {
  22. username: "unknown"
  23. };
  24. },
  25. mounted() {
  26. this.getUsernameFromId(this.$props.userId).then(username => {
  27. if (username) this.username = username;
  28. });
  29. },
  30. methods: {
  31. ...mapActions("user/auth", ["getUsernameFromId"])
  32. }
  33. };
  34. </script>
  35. <style lang="scss" scoped>
  36. a {
  37. color: var(--primary-color);
  38. &:hover,
  39. &:focus {
  40. filter: brightness(90%);
  41. }
  42. }
  43. </style>