微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 NativeScript-Vue 和 ListView 中管理数组大小

如何解决在 NativeScript-Vue 和 ListView 中管理数组大小

我有一个带有无限滚动的 ListView,我从使用 axios 的分页 API 调用填充。

如何管理数组的大小以获得良好的应用程序性能?加载新对象时是否必须从数组中剪切第一个对象?稍后,该数组将在 Vuex 中。

例如:API 调用返回 10 个新对象,数组中有 100 个活动对象,后端数据库中有 1000 个,ListView 显示 20 个,我从数组中删除了前 10 个对象?

<ListView for="post in posts" @loadMoreItems="loadMorePosts">
    <v-template>
        <Label :text="post.title" />
        <Label :text="post.body" />         
    </v-template>
</ListView>
data() {
    return {
        posts: [],links: {},};
},loadMorePosts() {
    var that = this;
    axios.defaults.headers.common = {'Authorization': 'Bearer '+this.token}
    axios.get(this.links.next)
    .then(function (response) {
        that.posts = that.posts.concat(response.data.data);
        that.links = response.data.links;
     });
},

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。