Calling a getter with a parameter from inside a component (TypeError: getter is not a function) #1194
Answered
by
dreambo8563
sergiomartindev
asked this question in
Help and Questions
-
Quoting the documentation: <template>
<p>User 2: {{ getUserById(2) }}</p>
</template> The thing is that it only seems to work when you call the getter, passing it a parameter, from inside the template. But what I'm looking for is to call that getter from inside of my component's script . Store: getters: {
counterMultipliedBy: (state) => (multiplier) => state.counter * multiplier
}, Component: import { useTestStore } from './stores/test';
import { storeToRefs } from 'pinia';
const testStore = useTestStore();
const { counterMultipliedBy } = storeToRefs(testStore);
const counterMultipliedByThree = counterMultipliedBy(3); But then, a message warns me saying that "TypeError: counterMultipliedBy is not a function". Even though it returns a function. Any idea? 🙏 |
Beta Was this translation helpful? Give feedback.
Answered by
dreambo8563
Apr 6, 2022
Replies: 1 comment 1 reply
-
@sergiomartindev , have a try like this. import { useTestStore } from './stores/test';
import { computed } from "@vue/reactivity";
const testStore = useTestStore();
const counterMultipliedByThree = computed(()=>testStore.counterMultipliedBy(3)); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
sergiomartindev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sergiomartindev , have a try like this.