Follower.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :md="4">
  5. <el-menu
  6. :default-active="this.$route.path"
  7. router
  8. class="el-menu-vertical-demo"
  9. >
  10. <el-menu-item v-for="(item,i) in navList" :key="i" :index="item.path">
  11. <i :class="item.icon" />
  12. <span slot="title">{{ item.name }}</span>
  13. </el-menu-item>
  14. </el-menu>
  15. </el-col>
  16. <el-col :md="20">
  17. <el-row v-for="(user, index) in followerList" :key="index" :md="16" :sm="12" :xs="12">
  18. <router-link target="_blank" :to="`/user/` + user.userId">
  19. <el-col :md="1">
  20. <el-avatar>
  21. <el-image :src="user.avatarUrl" />
  22. </el-avatar>
  23. </el-col>
  24. <el-col :md="15">
  25. <span>{{ user.screenName }}</span>
  26. </el-col>
  27. </router-link>
  28. <el-col :md="4">
  29. <el-button
  30. type="danger"
  31. size="mini"
  32. :icon="followButton.icon"
  33. @click="followUser(user.userId)"
  34. >
  35. <span>{{followButton.text}}</span>
  36. </el-button>
  37. </el-col>
  38. </el-row>
  39. </el-col>
  40. </el-row>
  41. </div>
  42. </template>
  43. <script>
  44. import { getUserInfo, getUserFollower } from "@/api/user";
  45. export default {
  46. name: 'Follower',
  47. data() {
  48. return {
  49. userId: -1,
  50. navList: [],
  51. followerList: [],
  52. followButton: {
  53. icon: 'el-icon-plus',
  54. text: '关注'
  55. },
  56. }
  57. },
  58. created() {
  59. this.userId = this.$route.params.id
  60. this.navList = this.getNavList(this.userId)
  61. getUserInfo(this.userId).then(res => {
  62. if (res.code === 0) {
  63. this.user = res.data
  64. document.title = this.user.screenName + '的关注列表'
  65. }
  66. })
  67. getUserFollower(this.userId).then(res => {
  68. if (res.code === 0) {
  69. this.followerList = res.data
  70. }
  71. })
  72. },
  73. methods: {
  74. getNavList(userId) {
  75. return [
  76. { path: '/user/' + userId + '/following', name: '关注', icon: 'el-icon-user' },
  77. { path: '/user/' + userId + '/follower', name: '粉丝', icon: 'el-icon-user' }
  78. ]
  79. },
  80. followUser(userId) {
  81. if (this.followButton.text === '关注') {
  82. console.log('关注用户')
  83. this.followButton.text = '已关注'
  84. this.followButton.icon = 'el-icon-check'
  85. } else {
  86. console.log('取消关注用户')
  87. this.followButton.text = '关注'
  88. this.followButton.icon = 'el-icon-plus'
  89. }
  90. },
  91. }
  92. }
  93. </script>