Better support for Vuex strict mode
See original GitHub issueHi,
I have a vue component, essentially like the below, allowing user to edit myCopy
with v-model
fields, then commit or reject the changes.
<template>
<div v-if="myCopy">
<input v-model="myCopy.title" type="text">
<input v-model="myCopy.text" type="text">
<button @click.prevent="commitCopy()">Save</button>
</div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
computed: {
...mapGetters("someService", {
myCopy: "getCopy"
})
},
methods: {
commitCopy() {
// Commit Copy stuff
},
}
};
</script>
This works great until i start to edit one of the input fields, and I get this error:
[vuex] Do not mutate vuex store state outside mutation handlers.
I can prevent the issue, by changing my store.js
file like this solution:
https://github.com/nuxt/nuxt.js/issues/1917#issuecomment-338471402
I don’t feel like that is the right answer, and was just wondering if the getCopy
getter should support a Two-way Computed Property like so:
https://vuex.vuejs.org/en/forms.html
Many thanks
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Strict Mode | Vuex
In strict mode, whenever Vuex state is mutated outside of mutation handlers, an error will be thrown. This ensures that all state mutations ......
Read more >VueX Strict Mode - Write better forms while keeping ... - YouTube
VueX Strict Mode - Write better forms while keeping all VueX State changes inside mutation ; https://www.vuescreencasts.com/course... ; 0:00 Start ...
Read more >Enabling strict mode while developing - Vuex Quick ... - O'Reilly
When Vuex is in strict mode, it will throw an error if the single state tree is mutated outside mutation handlers. This is...
Read more >VueX Strict Mode - Write better forms while keeping ... - Reddit
VueX Strict Mode - Write better forms while keeping all VueX State changes inside mutations (fixed) ... I posted a version of this...
Read more >Form Handling in Vuex Strict Mode | Ji ZHANG's Blog
Vue's computed property supports getter and setter, we can use it as a bridge between Vuex store and component. One limitation is computed ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My issue was that some parent scope data was being changed outside the async block. The solution is to define anything you modify in the same block.
Bad when you have more than 1 page:
Good always:
In this example
sm.p
doesn’t trigger the error because i’m not modifying it’s values, only a reference.I’m really glad you opened this issue because it got me thinking more about strict mode. I thought that adhering to
strict
mode would definitely be a problem for the relational stuff that I’m working on. I just tested it out and it seems that, thankfully, all of my efforts will not be in vain!So here’s a preview of what’s coming: Suppose you had an API that returns
/todos
data in the following format, where the todo record has anitemId
and theitem
is populated as part of the response:I’ve got it currently setup so that when this todo is inserted in the store,
feathers-vuex
will store the todo in thetodos
store, as you’d expect, but it will first automatically create theitem
in theitems
service store. When the todo instance is stored, it contains a reference to the item in theitems
store. I thought that due to the waystrict
mode is setup, it would have a fit with this, even if you used a mutation to make the changes. The good news is that it works without errors as long as you use a mutation!Here’s a mostly-full example:
So, if everything works out, this will all work in
strict
mode. It works in the tests, but I have to still test it out in a production app.