UserIdToUsername.vue 569 B

123456789101112131415161718192021222324252627282930313233
  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: ["userId", "link"],
  17. data() {
  18. return {
  19. username: "unknown"
  20. };
  21. },
  22. methods: {
  23. ...mapActions("user/auth", ["getUsernameFromId"])
  24. },
  25. mounted() {
  26. this.getUsernameFromId(this.$props.userId).then(res => {
  27. if (res) this.username = res;
  28. });
  29. }
  30. };
  31. </script>