Vue component doesn´t rerender after vuex state change The Next CEO of Stack OverflowVue.js components internal state being reused when underlying data changesHow to manage nested arrays in Vuex Store and pass it trough componentVuex state Map value changes don't propagateVue2 + Vuex Commit Not Committing (without Vue devtools)Vuex + Mocha: Committing mutations in tests throws warning 'Do not mutate vuex store state'Vue filter and the “Do not mutate vuex store state outside mutation handlers”Use/modify vuex state directly in templateComponent not updating on store change - VuexVuex unexpectedly updates 2 state objectsVuex State Object Detection in Typescript Vue
Can you replace a racial trait cantrip when leveling up?
Is it professional to write unrelated content in an almost-empty email?
Indicator light circuit
Sending manuscript to multiple publishers
Why didn't Khan get resurrected in the Genesis Explosion?
Is it possible to search for a directory/file combination?
How did people program for Consoles with multiple CPUs?
Written every which way
Bold, vivid family
How do I go from 300 unfinished/half written blog posts, to published posts?
How to avoid supervisors with prejudiced views?
What happened in Rome, when the western empire "fell"?
Make solar eclipses exceedingly rare, but still have new moons
Is micro rebar a better way to reinforce concrete than rebar?
Do I need to enable Dev Hub in my PROD Org?
What was the first Unix version to run on a microcomputer?
How to transpose the 1st and -1th levels of arbitrarily nested array?
What expression will give age in years in QGIS?
Is there a way to save my career from absolute disaster?
Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?
Why has the US not been more assertive in confronting Russia in recent years?
Is HostGator storing my password in plaintext?
Non-deterministic sum of floats
What does convergence in distribution "in the Gromov–Hausdorff" sense mean?
Vue component doesn´t rerender after vuex state change
The Next CEO of Stack OverflowVue.js components internal state being reused when underlying data changesHow to manage nested arrays in Vuex Store and pass it trough componentVuex state Map value changes don't propagateVue2 + Vuex Commit Not Committing (without Vue devtools)Vuex + Mocha: Committing mutations in tests throws warning 'Do not mutate vuex store state'Vue filter and the “Do not mutate vuex store state outside mutation handlers”Use/modify vuex state directly in templateComponent not updating on store change - VuexVuex unexpectedly updates 2 state objectsVuex State Object Detection in Typescript Vue
My vue component doesn´t change a child component when the state of vuex changes.
I have a list of slots for items and want to render items depending on a vuex state variable.
When you click on a "item"-component it sets the selectedItem state variable. Another component watches this variable and sets equippedItems variable with new data.
But when I try to change an item it doesn't show up, even though the state seems to change in Vuex.
I have set up the vuex store like that:
const state =
equippedItems:
[
name: 'Item 1',
strength: 3,
itemType: 1,
rarity: 3
,
name: 'Item 2',
strength: 40,
itemType: 2,
rarity: 2
],
selectedItem: null
const getters =
getEquippedItems: (state) => state.equippedItems,
getSelectedItem: (state) => state.selectedItem
const mutations =
changeSelectedItem: (state, newItem) =>
state.selectedItem = newItem;
,
changeEquippedItems: (state, parameters) =>
state.equippedItems[parameters[0]] = parameters[1];
const actions =
setSelectedItem( commit , index)
commit('changeSelectedItem', index);
,
setNewEquipment( commit , parameters)
commit('changeEquippedItems', parameters);
export default
state,
getters,
actions,
mutations
Then I have a component that sets the items according to the equippedItems variable
import mapGetters, mapActions from 'vuex';
import Item from '../Item';
export default
name: 'equipped-items',
components:
Item
,
props: [],
data()
return
chooseHead: false,
,
computed:
...mapGetters(['getEquippedItems', 'getItems', 'getSelectedItem'])
,
methods:
...mapActions(['setNewEquipment']),
chooseNewHead()
this.chooseHead = !this.chooseHead;
,
watch:
getSelectedItem: function ()
if (this.chooseHead)
this.setNewEquipment([0, this.getSelectedItem]);
<section class="equipped-items">
<div @click="chooseNewHead" class="head equipSlot">
<Item v-if="getEquippedItems[0]" :passedItem="getEquippedItems[0]" :parent="'equip'"> </Item>
</div>
<div class="body equipSlot">
<Item v-if="getEquippedItems[1]" :passedItem="getEquippedItems[1]"></Item>
</div>
</section>
Then there is the item component which sets the vuex variable selectedItem on click.
import mapActions from 'vuex';
export default
name: 'Item',
props: ['passedItem', 'parent'],
methods:
...mapActions(['setSelectedItem']),
selectedItem()
if (this.parent != 'equip')
this.setSelectedItem(this.passedItem);
It renders fine the first time when the page is loading, but doesn't change the new passed item to the item-component.
Thanks in advance
vue.js vuex
add a comment |
My vue component doesn´t change a child component when the state of vuex changes.
I have a list of slots for items and want to render items depending on a vuex state variable.
When you click on a "item"-component it sets the selectedItem state variable. Another component watches this variable and sets equippedItems variable with new data.
But when I try to change an item it doesn't show up, even though the state seems to change in Vuex.
I have set up the vuex store like that:
const state =
equippedItems:
[
name: 'Item 1',
strength: 3,
itemType: 1,
rarity: 3
,
name: 'Item 2',
strength: 40,
itemType: 2,
rarity: 2
],
selectedItem: null
const getters =
getEquippedItems: (state) => state.equippedItems,
getSelectedItem: (state) => state.selectedItem
const mutations =
changeSelectedItem: (state, newItem) =>
state.selectedItem = newItem;
,
changeEquippedItems: (state, parameters) =>
state.equippedItems[parameters[0]] = parameters[1];
const actions =
setSelectedItem( commit , index)
commit('changeSelectedItem', index);
,
setNewEquipment( commit , parameters)
commit('changeEquippedItems', parameters);
export default
state,
getters,
actions,
mutations
Then I have a component that sets the items according to the equippedItems variable
import mapGetters, mapActions from 'vuex';
import Item from '../Item';
export default
name: 'equipped-items',
components:
Item
,
props: [],
data()
return
chooseHead: false,
,
computed:
...mapGetters(['getEquippedItems', 'getItems', 'getSelectedItem'])
,
methods:
...mapActions(['setNewEquipment']),
chooseNewHead()
this.chooseHead = !this.chooseHead;
,
watch:
getSelectedItem: function ()
if (this.chooseHead)
this.setNewEquipment([0, this.getSelectedItem]);
<section class="equipped-items">
<div @click="chooseNewHead" class="head equipSlot">
<Item v-if="getEquippedItems[0]" :passedItem="getEquippedItems[0]" :parent="'equip'"> </Item>
</div>
<div class="body equipSlot">
<Item v-if="getEquippedItems[1]" :passedItem="getEquippedItems[1]"></Item>
</div>
</section>
Then there is the item component which sets the vuex variable selectedItem on click.
import mapActions from 'vuex';
export default
name: 'Item',
props: ['passedItem', 'parent'],
methods:
...mapActions(['setSelectedItem']),
selectedItem()
if (this.parent != 'equip')
this.setSelectedItem(this.passedItem);
It renders fine the first time when the page is loading, but doesn't change the new passed item to the item-component.
Thanks in advance
vue.js vuex
1
I can't see how the click is meant to change things - it looks like it only callschooseNewHeadwhich just toggles the state ofchooseHead?
– match
Mar 8 at 14:33
In the "item" component is the function "selectedItem" which sets the vuex variable "selectedItem". In my other component it watches for changes on these variable and changes the equippedItems variable accordingly
– Skarzan
Mar 8 at 14:43
add a comment |
My vue component doesn´t change a child component when the state of vuex changes.
I have a list of slots for items and want to render items depending on a vuex state variable.
When you click on a "item"-component it sets the selectedItem state variable. Another component watches this variable and sets equippedItems variable with new data.
But when I try to change an item it doesn't show up, even though the state seems to change in Vuex.
I have set up the vuex store like that:
const state =
equippedItems:
[
name: 'Item 1',
strength: 3,
itemType: 1,
rarity: 3
,
name: 'Item 2',
strength: 40,
itemType: 2,
rarity: 2
],
selectedItem: null
const getters =
getEquippedItems: (state) => state.equippedItems,
getSelectedItem: (state) => state.selectedItem
const mutations =
changeSelectedItem: (state, newItem) =>
state.selectedItem = newItem;
,
changeEquippedItems: (state, parameters) =>
state.equippedItems[parameters[0]] = parameters[1];
const actions =
setSelectedItem( commit , index)
commit('changeSelectedItem', index);
,
setNewEquipment( commit , parameters)
commit('changeEquippedItems', parameters);
export default
state,
getters,
actions,
mutations
Then I have a component that sets the items according to the equippedItems variable
import mapGetters, mapActions from 'vuex';
import Item from '../Item';
export default
name: 'equipped-items',
components:
Item
,
props: [],
data()
return
chooseHead: false,
,
computed:
...mapGetters(['getEquippedItems', 'getItems', 'getSelectedItem'])
,
methods:
...mapActions(['setNewEquipment']),
chooseNewHead()
this.chooseHead = !this.chooseHead;
,
watch:
getSelectedItem: function ()
if (this.chooseHead)
this.setNewEquipment([0, this.getSelectedItem]);
<section class="equipped-items">
<div @click="chooseNewHead" class="head equipSlot">
<Item v-if="getEquippedItems[0]" :passedItem="getEquippedItems[0]" :parent="'equip'"> </Item>
</div>
<div class="body equipSlot">
<Item v-if="getEquippedItems[1]" :passedItem="getEquippedItems[1]"></Item>
</div>
</section>
Then there is the item component which sets the vuex variable selectedItem on click.
import mapActions from 'vuex';
export default
name: 'Item',
props: ['passedItem', 'parent'],
methods:
...mapActions(['setSelectedItem']),
selectedItem()
if (this.parent != 'equip')
this.setSelectedItem(this.passedItem);
It renders fine the first time when the page is loading, but doesn't change the new passed item to the item-component.
Thanks in advance
vue.js vuex
My vue component doesn´t change a child component when the state of vuex changes.
I have a list of slots for items and want to render items depending on a vuex state variable.
When you click on a "item"-component it sets the selectedItem state variable. Another component watches this variable and sets equippedItems variable with new data.
But when I try to change an item it doesn't show up, even though the state seems to change in Vuex.
I have set up the vuex store like that:
const state =
equippedItems:
[
name: 'Item 1',
strength: 3,
itemType: 1,
rarity: 3
,
name: 'Item 2',
strength: 40,
itemType: 2,
rarity: 2
],
selectedItem: null
const getters =
getEquippedItems: (state) => state.equippedItems,
getSelectedItem: (state) => state.selectedItem
const mutations =
changeSelectedItem: (state, newItem) =>
state.selectedItem = newItem;
,
changeEquippedItems: (state, parameters) =>
state.equippedItems[parameters[0]] = parameters[1];
const actions =
setSelectedItem( commit , index)
commit('changeSelectedItem', index);
,
setNewEquipment( commit , parameters)
commit('changeEquippedItems', parameters);
export default
state,
getters,
actions,
mutations
Then I have a component that sets the items according to the equippedItems variable
import mapGetters, mapActions from 'vuex';
import Item from '../Item';
export default
name: 'equipped-items',
components:
Item
,
props: [],
data()
return
chooseHead: false,
,
computed:
...mapGetters(['getEquippedItems', 'getItems', 'getSelectedItem'])
,
methods:
...mapActions(['setNewEquipment']),
chooseNewHead()
this.chooseHead = !this.chooseHead;
,
watch:
getSelectedItem: function ()
if (this.chooseHead)
this.setNewEquipment([0, this.getSelectedItem]);
<section class="equipped-items">
<div @click="chooseNewHead" class="head equipSlot">
<Item v-if="getEquippedItems[0]" :passedItem="getEquippedItems[0]" :parent="'equip'"> </Item>
</div>
<div class="body equipSlot">
<Item v-if="getEquippedItems[1]" :passedItem="getEquippedItems[1]"></Item>
</div>
</section>
Then there is the item component which sets the vuex variable selectedItem on click.
import mapActions from 'vuex';
export default
name: 'Item',
props: ['passedItem', 'parent'],
methods:
...mapActions(['setSelectedItem']),
selectedItem()
if (this.parent != 'equip')
this.setSelectedItem(this.passedItem);
It renders fine the first time when the page is loading, but doesn't change the new passed item to the item-component.
Thanks in advance
vue.js vuex
vue.js vuex
edited Mar 8 at 14:27
James Coyle
5,53311638
5,53311638
asked Mar 8 at 14:15
SkarzanSkarzan
1
1
1
I can't see how the click is meant to change things - it looks like it only callschooseNewHeadwhich just toggles the state ofchooseHead?
– match
Mar 8 at 14:33
In the "item" component is the function "selectedItem" which sets the vuex variable "selectedItem". In my other component it watches for changes on these variable and changes the equippedItems variable accordingly
– Skarzan
Mar 8 at 14:43
add a comment |
1
I can't see how the click is meant to change things - it looks like it only callschooseNewHeadwhich just toggles the state ofchooseHead?
– match
Mar 8 at 14:33
In the "item" component is the function "selectedItem" which sets the vuex variable "selectedItem". In my other component it watches for changes on these variable and changes the equippedItems variable accordingly
– Skarzan
Mar 8 at 14:43
1
1
I can't see how the click is meant to change things - it looks like it only calls
chooseNewHead which just toggles the state of chooseHead ?– match
Mar 8 at 14:33
I can't see how the click is meant to change things - it looks like it only calls
chooseNewHead which just toggles the state of chooseHead ?– match
Mar 8 at 14:33
In the "item" component is the function "selectedItem" which sets the vuex variable "selectedItem". In my other component it watches for changes on these variable and changes the equippedItems variable accordingly
– Skarzan
Mar 8 at 14:43
In the "item" component is the function "selectedItem" which sets the vuex variable "selectedItem". In my other component it watches for changes on these variable and changes the equippedItems variable accordingly
– Skarzan
Mar 8 at 14:43
add a comment |
1 Answer
1
active
oldest
votes
There a couple mistakes in your code:
1- I couldn't identify where you call/trigger an event to your selectedItem() method in your component.
2-(This is an extra) If you want to append objects to an array injavascript you just use array.push(odject), so i would suggest you to change your changeEquippedItems mutation to:
changeEquippedItems: (state, parameters) =>
state.equippedItems.push(parameters);
The event is triggered in the html section of the item component. And i don´t try to push new items in the array. i want to change them. The first element represents the first item, the second the second item and so on
– Skarzan
Mar 8 at 15:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065045%2fvue-component-doesn%25c2%25b4t-rerender-after-vuex-state-change%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There a couple mistakes in your code:
1- I couldn't identify where you call/trigger an event to your selectedItem() method in your component.
2-(This is an extra) If you want to append objects to an array injavascript you just use array.push(odject), so i would suggest you to change your changeEquippedItems mutation to:
changeEquippedItems: (state, parameters) =>
state.equippedItems.push(parameters);
The event is triggered in the html section of the item component. And i don´t try to push new items in the array. i want to change them. The first element represents the first item, the second the second item and so on
– Skarzan
Mar 8 at 15:10
add a comment |
There a couple mistakes in your code:
1- I couldn't identify where you call/trigger an event to your selectedItem() method in your component.
2-(This is an extra) If you want to append objects to an array injavascript you just use array.push(odject), so i would suggest you to change your changeEquippedItems mutation to:
changeEquippedItems: (state, parameters) =>
state.equippedItems.push(parameters);
The event is triggered in the html section of the item component. And i don´t try to push new items in the array. i want to change them. The first element represents the first item, the second the second item and so on
– Skarzan
Mar 8 at 15:10
add a comment |
There a couple mistakes in your code:
1- I couldn't identify where you call/trigger an event to your selectedItem() method in your component.
2-(This is an extra) If you want to append objects to an array injavascript you just use array.push(odject), so i would suggest you to change your changeEquippedItems mutation to:
changeEquippedItems: (state, parameters) =>
state.equippedItems.push(parameters);
There a couple mistakes in your code:
1- I couldn't identify where you call/trigger an event to your selectedItem() method in your component.
2-(This is an extra) If you want to append objects to an array injavascript you just use array.push(odject), so i would suggest you to change your changeEquippedItems mutation to:
changeEquippedItems: (state, parameters) =>
state.equippedItems.push(parameters);
edited Mar 8 at 15:27
answered Mar 8 at 14:47
Edgencio Da CalistaEdgencio Da Calista
1357
1357
The event is triggered in the html section of the item component. And i don´t try to push new items in the array. i want to change them. The first element represents the first item, the second the second item and so on
– Skarzan
Mar 8 at 15:10
add a comment |
The event is triggered in the html section of the item component. And i don´t try to push new items in the array. i want to change them. The first element represents the first item, the second the second item and so on
– Skarzan
Mar 8 at 15:10
The event is triggered in the html section of the item component. And i don´t try to push new items in the array. i want to change them. The first element represents the first item, the second the second item and so on
– Skarzan
Mar 8 at 15:10
The event is triggered in the html section of the item component. And i don´t try to push new items in the array. i want to change them. The first element represents the first item, the second the second item and so on
– Skarzan
Mar 8 at 15:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55065045%2fvue-component-doesn%25c2%25b4t-rerender-after-vuex-state-change%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I can't see how the click is meant to change things - it looks like it only calls
chooseNewHeadwhich just toggles the state ofchooseHead?– match
Mar 8 at 14:33
In the "item" component is the function "selectedItem" which sets the vuex variable "selectedItem". In my other component it watches for changes on these variable and changes the equippedItems variable accordingly
– Skarzan
Mar 8 at 14:43