can use storeToRefs
get action?
#1008
-
counter.js import { defineStore } from "pinia";
export const useCounterStore = defineStore("counter", {
state: () => {
return {
counter: 0,
};
},
actions: {
increment() {
this.counter++;
},
},
}); App.vue <script setup>
import { storeToRefs } from "pinia";
import { useCounterStore } from "./counter.js";
const couterStore = useCounterStore();
const { counter, increment } = storeToRefs(couterStore);
console.log(counter); //ObjectRefImpl
console.log(increment); //undefined
</script>
<template>
<button>{{ counter }}</button>
</template>
Is it a limitation of pinia Or am I doing something wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
soc221b
Jan 29, 2022
Replies: 1 comment 1 reply
-
This behavior is similar to Use this instead: <script setup>
import { storeToRefs } from "pinia";
import { useCounterStore } from "./counter.js";
const couterStore = useCounterStore();
- const { counter, increment } = storeToRefs(couterStore);
+ const { counter } = storeToRefs(couterStore);
console.log(counter); //ObjectRefImpl
- console.log(increment); //undefined
+ console.log(couterStore.increment);
</script>
<template>
<button>{{ counter }}</button>
</template> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
storeToRefs
This behavior is similar to
toRefs
Use this instead: