Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list not render after vuex state set to empty #121

Open
czjge opened this issue Jan 25, 2019 · 4 comments
Open

list not render after vuex state set to empty #121

czjge opened this issue Jan 25, 2019 · 4 comments

Comments

@czjge
Copy link

czjge commented Jan 25, 2019

I'm using this repository to build my blog with vuex, but I got a problem: a vuex state set to empty, and I change that state to none-empty, the problem comes, the list can't be rendered, but the page links can be rendered. I check the api and the state, both are ok. now I'm pretty sure the problem is the view render. Here is the code:

<template>
    <div>
        <ul class="list-group" style="margin-left: -40px;">
            <paginate
                    name="articles"
                    :list="lists"
                    :per="2"
            >
                <li class="list-group-item"
                    v-for="row in paginated('articles')">
                    <router-link :to="{path:'/' + row.id}" class="text-muted lead">
                        {{ row.title }}
                    </router-link>
                    &nbsp;&nbsp;&nbsp;
                    <span class="small text-muted">Posted&nbsp;{{ row.created }}</span>
                </li>
            </paginate>
        </ul>
        <paginate-links
                for="articles"
        >
        </paginate-links>
    </div>
</template>

<script>
    import { mapState, mapActions } from 'vuex';

    export default {
        name: "PostCategory",
        computed: mapState({
            lists: state => state.post.categories
        }),
        watch: {
            lists: function () {
                console.log(this.lists)
            }
        },
        created() {
            var cate_id = this.$route.params.cate_id;
            this.getPostCategory(cate_id);
        },
        beforeRouteUpdate (to, from, next) {
            // react to route changes...
            // don't forget to call next()
            var cate_id = to.params.cate_id;
            this.getPostCategory(cate_id);
        },
        methods: {
            ...mapActions([
                'getPostCategory'
            ])
        },
        data () {
            return {
                paginate: ['articles'],
            }
        }
    }
</script>
@mrodrig
Copy link

mrodrig commented Apr 8, 2019

I'm running into a similar issue without VueX. I have an array of objects and if the array is filtered down to an empty list when a user searches on specific text, then the paginated(...) function will always return an empty list, even if the search term changes back to something that previously returned several results.

@jchamb
Copy link

jchamb commented Apr 10, 2019

@czjge @mrodrig I'm not sure this is being maintained anymore since it hasn't been updated in over a year. There was a pull request that fixes this #99 I created my own fork to apply the patch to fix it.

you can do the same in your own fork for the time being or for a quick work around change your package to hit mine.

In package.json
"vue-paginate": "git+ssh://git@github.com:jchamb/vue-paginate.git#v3.6.1"

@mikerogne
Copy link

Thanks, fixes it for me!

@shequet
Copy link

shequet commented Nov 21, 2020

Thank you for your correction, it works great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants