Table sort triggers [vuex] Do not mutate vuex store state outside mutation handlers
See original GitHub issueWhen sorting the a table rendered with the code below:
<template>
<b-table striped hover :items="items" :fields="fields">
<template slot="username" scope="item">
{{item.item.username}}
</template>
<template slot="isActive" scope="item">
{{item.item.active?'Yes :)':'No :('}}
</template>
<template slot="email" scope="item">
{{item.item.Email}}
</template>
</b-table>
</template>
<script>
export default {
name: 'variant-table',
props: ['items'],
data: function () {
return {
fields: {
username: {
label: 'Username',
sortable: true
},
isActive: {
label: 'is Active'
},
email: {
label: 'E-mail'
}
},
filter: null
}
}
}
</script>
My console throws a Vuex warning to not mutate the store state outside mutation handlers. I don’t feel that disabling strict: true in my store is the way to go.
Could it be a Vuex error inside the boostrap-vue package?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
do not mutate vuex store state outside mutation - Stack Overflow
SO - to fix that, you'll want to only commit the mutation in the set() handler of your computed property. Then, add an...
Read more >Do not mutate vuex store state outside mutation handlers
Now this table is draggable / sortable so this changes the “records” so in the dragReorder method first thing I do is clone...
Read more >Mutate Vuex state directly without using mutations-Vue.js
One of them is that you can make a reactive object outside of your Vue components, import that object into your components as...
Read more >Mutation Not Committing State Vuex - Nuxt - ADocLib
Stack Overflow works best with JavaScript enabled, Where Vuex inside nuxt app throws Do not mutate vuex store state outside mutation handlers!
Read more >vuex do not mutate vuex store state outside mutation handlers ...
const items = JSON.parse(JSON.stringify(this.$store.getters['cart/items']))
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
Table details needs to use Vue’s
$set(...)
method in order to update the row’s details flag in the record data, which triggers the display of the details scoped slot.Currently b-table creates a shallow
slice()
of the items array so that the order of the orignal table order is not mutated. But it doesn’t copy the rows data, rather it maintains the original record object reference.We had, a few versions ago, switched to a deep copy of the record data, but many people were relying on the data being a reference to the actual data, and the ability to mutate it, so we switched back to using just a slice of the original items array. Not to mention, the overhead that was introduced by the deep copy (slowing the responsiveness of the table) and the lack of ability to clone certain data types and function references (loosing their
this
bound reference).@Mark-de-Haan @piotrekfracek Thanks for reporting. 6e1f0a2 should resolve this problem by cloning data when filtering/sorting using
slice()
and JSON trick is not needed anymore.