follow.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="page">
  3. <view class="tabs">
  4. <view class="tab"
  5. :class="{ active: activeTab === 'follow' }"
  6. @click="switchTab('follow')">关注</view>
  7. <view class="tab"
  8. :class="{ active: activeTab === 'fans' }"
  9. @click="switchTab('fans')">粉丝</view>
  10. </view>
  11. <view class="follow-list">
  12. <view class="follow-item" v-for="(item, index) in currentList" :key="index">
  13. <image class="avatar" :src="item.avatar" mode="aspectFill"></image>
  14. <view class="info">
  15. <view class="name">{{item.name}}</view>
  16. <view class="desc">{{item.description}}</view>
  17. </view>
  18. <button class="unfollow-btn" @click="toggleFollow(item)">
  19. {{item.isFollowing ? '取消关注' : '关注'}}
  20. </button>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. activeTab: 'follow', // 当前激活的标签
  30. followList: [
  31. {
  32. avatar: '/static/demo/avatar1.jpg',
  33. name: '冷落',
  34. description: 'AI设计师',
  35. isFollowing: true
  36. },
  37. {
  38. avatar: '/static/demo/avatar2.jpg',
  39. name: '雾里',
  40. description: '感谢你的关注,远方的陌生人',
  41. isFollowing: true
  42. }
  43. ],
  44. fansList: [
  45. {
  46. avatar: '/static/demo/avatar3.jpg',
  47. name: '小明',
  48. description: '热爱生活的人',
  49. isFollowing: false
  50. },
  51. {
  52. avatar: '/static/demo/avatar4.jpg',
  53. name: '阳光',
  54. description: '摄影师',
  55. isFollowing: true
  56. }
  57. ]
  58. }
  59. },
  60. computed: {
  61. // 根据当前标签返回对应的列表数据
  62. currentList() {
  63. return this.activeTab === 'follow' ? this.followList : this.fansList;
  64. }
  65. },
  66. methods: {
  67. // 切换标签
  68. switchTab(tab) {
  69. this.activeTab = tab;
  70. },
  71. toggleFollow(item) {
  72. item.isFollowing = !item.isFollowing;
  73. // 这里可以添加调用后端API的逻辑
  74. }
  75. }
  76. }
  77. </script>
  78. <style scoped lang="scss">
  79. @import 'follow.scss';
  80. </style>