Is it OK to update props if they are coming from a Pinia store? #1645
Unanswered
djave-co
asked this question in
Help and Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I usually use Vue2 to just quickly knock up a single file app. I am now using vue3, mulitiple components and pinia.
It would really help for someone to explain the basics of components to me, with regard to updating a store.
My limited experience of using components is that you never update the props. That said, I have an app (bare bones below) where I am using
v-model
successfully on the props.I have a Form, and have created the following state for it:
Now in my form component, I plan on having something like this:
This renders nicely, and in my AdminField I use v-model:
In my @change function I'd like to create a key if one doesn't exist, so now I am doing things like this:
So here I am directly modifying the props, not even through v-model. This all works great, I'm just a bit worried after reading things like this:
https://vuejs.org/guide/components/props.html#one-way-data-flow
Can anyone advise if what I'm doing OK, or if not, the best way to refactor what I have? I looked into mutations, but I couldn't work out if I should be passing a unique id or something to the AdminField, then mutating the store from there, or if I should be
$emitting
like I used to in Vue2, then adding some very complex listener to the component node like<AdminField @updated="$store.commit({screenIndex: s, fieldIndex: f})" />
to then update the store.Beta Was this translation helpful? Give feedback.
All reactions