Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

david001's avatar

Maintain state of filters vue

I am using vue3 and I am pushing filter params to URL. I want to maintain the state of filter even after the page refresh. For single options like dropdown the state of filter remain even after page refresh but for checkbox it won't. If I check some courses checkbox , it push params to URL but when I refresh, the checkbox will remain unchecked. Any help? Here is my code

<template>
    <div>Filters</div>
    <form action="#">
        <div>
            <h3>Choose multiple</h3>
  
     
        </div>
         
        <select   v-model="filter.sort">
            <option value="">Sort by</option>
            <option value="latest">Latest</option>
            <option value="popular">Popular</option>
        </select>
        <select  v-model="filter.limit">
            <option value="">Show</option>
            <option value="55">55</option>
            <option value="70">70</option>
        </select>


    </form>
</template>

<script>
export default {
    data(){
        return{
            
    
            filter: {
                sort:this.$route.query.sort,
                limit:this.$route.query.limit,
               
               
           
           }
        }
    },

    watch:{
        filter:{
            handler(){
         
            this.$router.push({
                query:this.filter
            })
            },
            deep:true
        }
    }
}
</script>
0 likes
4 replies
vincent15000's avatar

To check the content of filter.course, you can add {{ filter.course }} in the view.

What contains filter.course ?

vincent15000's avatar

@david001 I don't understand why ... have you tried to store your state in the VueJS store ? each time it is changed, you store the new value, and when you need it, you retrieve it from the store.

1 like

Please or to participate in this conversation.