UserIdToUsername.vue 676 B

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