author-follow.vue 1.29 KB
<template>
  <Layout class="author-follow-page">
    <LayoutHeader slot='header' theme="white" class="author-page-header">{{isMine ? '我' : 'TA'}}的关注</LayoutHeader>
    <UserList ref="userList" :on-fetch="onFetch"></UserList>
  </Layout>
</template>

<script>
import UserList from './components/user-list';
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('user');

export default {
  name: 'authorFollow',
  data() {
    return {
      isMine: false
    };
  },
  created() {
    this._baseParams = {
      authorType: this.$route.params.type || 1,
      limit: 20,
    };
  },
  activated() {
    this.init(this.$route.params);
    this.$refs.userList.init();
  },
  beforeRouteUpdate(to, from, next) {
    this.init(to.params);
    this.$refs.userList.init();
    next();
  },
  methods: {
    ...mapActions(['authorAttentionList', 'authorMineAttentionList']),
    init(params) {
      this.isMine = !params.id;

      if (!this.isMine) {
        this._baseParams.authorUid = params.id;
      }
    },
    onFetch({page, lastedTime}) {
      let params = Object.assign({page, lastedTime}, this._baseParams);

      return this.isMine ? this.authorMineAttentionList(params) : this.authorAttentionList(params);
    }
  },
  components: {
    UserList
  }
};
</script>