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

laravel_ninja's avatar

Pinia State Management Issue

Hi I'm using Vue in Laravel application I've created a store in pinia in composition api pattern . It's a simple counter app but when I'm updating the value it does not gets updated at that time when I revisit the component then it showing updated value. Below is the code

import { defineStore } from "pinia";
import { ref } from "vue";
export const useCounterStore = defineStore("counter", () => {
    const counter = ref(0);
    function incrementCounter() {
        console.log("Incrementing counter");
        counter.value++;
    }
    function decrementCounter() {
        counter.value--;
    }
    return {
        counter,
        incrementCounter,
        decrementCounter,
    };
});

Here how I'm using it in component

<script setup>
import { useCounterStore } from "@/stores/counter.js";
const { counter, incrementCounter } = useCounterStore();
function handleClick() {
    console.log("clicked");
    incrementCounter();
}
</script>
<template>
    <button @click="handleClick">Pressed {{ counter }}</button>
</template>
0 likes
2 replies
lbecket's avatar

One thing you could try is the nextTick function from the Vue instance:

function handleClick() {
  console.log("clicked");
  this.$nextTick(() => {
    incrementCounter();
  });
}
azimidev's avatar

I don't see any issues to be honest but try this syntax and see if it works

counter.value += 1 
//or 
counter.value = counter.value + 1

Please or to participate in this conversation.