article.vue 2.53 KB
<template>
  <Layout>
    <LayoutHeader slot='header' title="推荐" :share="shareData"></LayoutHeader>
    <LayoutScroll :infinite="true" :on-fetch="onFetch">
      <div class="article-item" slot="item" slot-scope="{ data }">
        <AvatarGroup :avatars="avatarList"></AvatarGroup>
        <div :id="data.id" class="item">
          <div class="avatar" :style="{backgroundImage: 'url(' + (data.avatar || '') + ')'}"></div>
          <div class="bubble">
            <p>{{ data.name }}</p>
            <div class="meta">
              <time class="posted-date">{{ data.time }}</time>
            </div>
          </div>
        </div>
      </div>
    </LayoutScroll>
  </Layout>
</template>

<script>
import {createNamespacedHelpers} from 'vuex';
import {Scroll, Loading} from 'cube-ui';
const {mapState, mapActions, mapMutations} = createNamespacedHelpers('article');

export default {
  name: 'ArticlePage',
  components: {
    Loading,
    Scroll
  },
  data() {
    return {
      avatarList: [
        { src: '//tvax3.sinaimg.cn/crop.0.0.996.996.50/b2226be7ly8fwi9zpop35j20ro0roq45.jpg' },
        { src: '//tvax2.sinaimg.cn/crop.0.0.828.828.50/006IPkwKly8fyhr791kkxj30n00n0q3u.jpg' },
        { src: '//tvax3.sinaimg.cn/crop.0.0.996.996.50/005X6MlLly8fy8wodh5o6j30ro0rowh6.jpg' },
        { src: '//tvax3.sinaimg.cn/crop.0.0.888.888.50/005EQCcnly8fytqpipvdqj30oo0oo76b.jpg' },
        { src: '//tvax4.sinaimg.cn/crop.0.0.996.996.50/006Tjwsbly8fzhvo4bconj30ro0rodhk.jpg' },
        { src: '//tva2.sinaimg.cn/crop.0.0.512.512.50/67f23b64jw8ercxqrzo88j20e80e8q38.jpg' },
        { src: '//tva2.sinaimg.cn/crop.107.517.1137.1137.50/bda75d7bjw8eyqx9d5x3fj211x1kwk5v.jpg' },
        { src: '//tvax2.sinaimg.cn/crop.0.0.828.828.50/006IPkwKly8fyhr791kkxj30n00n0q3u.jpg' },
      ],
      list: [],
      shareData: {},
      scrollOptions: {
        bounce: false
      },
      inx: 0
    };
  },
  computed: {
    ...mapState(['articleList']),
  },
  methods: {
    onFetch() {
      const items = Array.from({length: 50}).map((v, i) => {
        return {
          name: 'chenfeng' + (i + 50 * this.inx)
        }
      })

      this.inx++;

      return Promise.resolve(items);
    },
    click() {
      this.$refs.actionSheet.show();
      setTimeout(() => {
        this.initData();
        this.forceUpdate();
      }, 1000);
    },
    forceUpdate() {
      this.$refs.scroll.forceUpdate();
    },
    initData() {
      for (let i = 0; i < 100; i++) {
        this.list.push(i);
      }
    }

  }
};
</script>

<style lang="scss" scoped>
.article-item {
  height: 100px;
}
</style>