UserIdToUsername.vue 693 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <router-link
  3. v-if="$props.link && username"
  4. :to="{ path: `/u/${userIdMap['Z' + $props.userId]}` }"
  5. >
  6. {{ username ? username : "unknown" }}
  7. </router-link>
  8. <span v-else>
  9. {{ username ? username : "unknown" }}
  10. </span>
  11. </template>
  12. <script>
  13. import { mapState, mapActions } from "vuex";
  14. export default {
  15. props: ["userId", "link"],
  16. data: function() {
  17. return {
  18. username: ""
  19. };
  20. },
  21. computed: {
  22. ...mapState("user/auth", {
  23. userIdMap: state => state.userIdMap
  24. })
  25. },
  26. methods: {
  27. ...mapActions("user/auth", ["getUsernameFromId"])
  28. },
  29. mounted: function() {
  30. this.getUsernameFromId(this.$props.userId).then(res => {
  31. this.username = res;
  32. });
  33. }
  34. };
  35. </script>