Iterating over a Vuex store object2019 Community Moderator ElectionHow to access vuex state objects?How await uploaded data from Vuex?Do vuex modules still require namespacing?How to update state in a component when the value changed at vuex store?Vuex computed properties only work with gettersIs there a way to use promise in action with this structure VuexVuex store getter emptyVuex actions, vuex modules and mapActions with custom nameVuex and firebase listenersVuex store getter always returning false
What Happens when Passenger Refuses to Fly Boeing 737 Max?
'The literal of type int is out of range' con número enteros pequeños (2 dígitos)
Intuition behind counterexample of Euler's sum of powers conjecture
An alternative proof of an application of Hahn-Banach
Is it possible to avoid unpacking when merging Association?
Bash script should only kill those instances of another script's that it has launched
What are the threaded holes in Manfrotto camera brackets?
Definition of Statistic
Find longest word in a string: are any of these algorithms good?
UART pins to unpowered MCU?
What problems would a superhuman have whose skin is constantly hot?
Plausibility of Mushroom Buildings
Is it necessary to separate DC power cables and data cables?
Good for you! in Russian
Can one live in the U.S. and not use a credit card?
Does this video of collapsing warehouse shelves show a real incident?
Did Carol Danvers really receive a Kree blood tranfusion?
Does a warlock using the Darkness/Devil's Sight combo still have advantage on ranged attacks against a target outside the Darkness?
Single word request: Harming the benefactor
What's the "normal" opposite of flautando?
Was Luke Skywalker the leader of the Rebel forces on Hoth?
Are all players supposed to be able to see each others' character sheets?
Filtering SOQL results with optional conditionals
What are some noteworthy "mic-drop" moments in math?
Iterating over a Vuex store object
2019 Community Moderator ElectionHow to access vuex state objects?How await uploaded data from Vuex?Do vuex modules still require namespacing?How to update state in a component when the value changed at vuex store?Vuex computed properties only work with gettersIs there a way to use promise in action with this structure VuexVuex store getter emptyVuex actions, vuex modules and mapActions with custom nameVuex and firebase listenersVuex store getter always returning false
I'm new to Vue.js and Vuex and trying out a sample app.
This is the scenario-
I have a store module for notifications which stores the notifications in an object with a given name as its key.
'message1':
type: 'info',
message: 'This is an info message.',
isShown: true,
,
'message2':
type: 'success',
message: 'This is a success message.',
isShown: true,
,
'message3':
type: 'error',
message: 'This is an error message.',
isShown: true,
And this is my Vuex module that handles notification-
const state =
notifications: ,
;
const mutations =
setNotification(state, message, type, name )
state.notifications[name] =
message,
type,
isShown: true,
,
removeNotification(state, name)
delete state.notifications[name];
;
const actions =
async showNotification(context, options)
await context.commit('setNotification', options);
,
async removeNotification(context, name)
await context.commit('removeNotification', name);
const getters =
isNotificationShown: (state, getters) =>
return getters.getNotificationMessageList.length > 0;
,
getNotificationMessageList: state =>
return state.notifications;
,
export default
state,
actions,
mutations,
getters,
And this is my component-
<template>
<div v-if="isShown">
<div v-for="(notice, name, index) in notificationMessageList" :key="name">
index - notice.type - notice.message
</div>
</div>
</template>
<script>
export default
computed:
isShown()
return this.$store.getters.isNotificationShown;
,
notificationMessageList()
return this.$store.getters.getNotificationMessageList;
,
,
;
</script>
I checked with the Vue Development tool and found that the store does get updated and so does the component with the notification messages that I'm passing to the store. But the component is not being rendered. But if I use the same data by hardcoding it in the component, it works.
I'm not sure if this is the right way to connect the Vuex store to a component.
vue.js vue-component vuex vuex-modules
add a comment |
I'm new to Vue.js and Vuex and trying out a sample app.
This is the scenario-
I have a store module for notifications which stores the notifications in an object with a given name as its key.
'message1':
type: 'info',
message: 'This is an info message.',
isShown: true,
,
'message2':
type: 'success',
message: 'This is a success message.',
isShown: true,
,
'message3':
type: 'error',
message: 'This is an error message.',
isShown: true,
And this is my Vuex module that handles notification-
const state =
notifications: ,
;
const mutations =
setNotification(state, message, type, name )
state.notifications[name] =
message,
type,
isShown: true,
,
removeNotification(state, name)
delete state.notifications[name];
;
const actions =
async showNotification(context, options)
await context.commit('setNotification', options);
,
async removeNotification(context, name)
await context.commit('removeNotification', name);
const getters =
isNotificationShown: (state, getters) =>
return getters.getNotificationMessageList.length > 0;
,
getNotificationMessageList: state =>
return state.notifications;
,
export default
state,
actions,
mutations,
getters,
And this is my component-
<template>
<div v-if="isShown">
<div v-for="(notice, name, index) in notificationMessageList" :key="name">
index - notice.type - notice.message
</div>
</div>
</template>
<script>
export default
computed:
isShown()
return this.$store.getters.isNotificationShown;
,
notificationMessageList()
return this.$store.getters.getNotificationMessageList;
,
,
;
</script>
I checked with the Vue Development tool and found that the store does get updated and so does the component with the notification messages that I'm passing to the store. But the component is not being rendered. But if I use the same data by hardcoding it in the component, it works.
I'm not sure if this is the right way to connect the Vuex store to a component.
vue.js vue-component vuex vuex-modules
Can you please create jsfiddle for this?
– varit05
Mar 7 at 7:56
add a comment |
I'm new to Vue.js and Vuex and trying out a sample app.
This is the scenario-
I have a store module for notifications which stores the notifications in an object with a given name as its key.
'message1':
type: 'info',
message: 'This is an info message.',
isShown: true,
,
'message2':
type: 'success',
message: 'This is a success message.',
isShown: true,
,
'message3':
type: 'error',
message: 'This is an error message.',
isShown: true,
And this is my Vuex module that handles notification-
const state =
notifications: ,
;
const mutations =
setNotification(state, message, type, name )
state.notifications[name] =
message,
type,
isShown: true,
,
removeNotification(state, name)
delete state.notifications[name];
;
const actions =
async showNotification(context, options)
await context.commit('setNotification', options);
,
async removeNotification(context, name)
await context.commit('removeNotification', name);
const getters =
isNotificationShown: (state, getters) =>
return getters.getNotificationMessageList.length > 0;
,
getNotificationMessageList: state =>
return state.notifications;
,
export default
state,
actions,
mutations,
getters,
And this is my component-
<template>
<div v-if="isShown">
<div v-for="(notice, name, index) in notificationMessageList" :key="name">
index - notice.type - notice.message
</div>
</div>
</template>
<script>
export default
computed:
isShown()
return this.$store.getters.isNotificationShown;
,
notificationMessageList()
return this.$store.getters.getNotificationMessageList;
,
,
;
</script>
I checked with the Vue Development tool and found that the store does get updated and so does the component with the notification messages that I'm passing to the store. But the component is not being rendered. But if I use the same data by hardcoding it in the component, it works.
I'm not sure if this is the right way to connect the Vuex store to a component.
vue.js vue-component vuex vuex-modules
I'm new to Vue.js and Vuex and trying out a sample app.
This is the scenario-
I have a store module for notifications which stores the notifications in an object with a given name as its key.
'message1':
type: 'info',
message: 'This is an info message.',
isShown: true,
,
'message2':
type: 'success',
message: 'This is a success message.',
isShown: true,
,
'message3':
type: 'error',
message: 'This is an error message.',
isShown: true,
And this is my Vuex module that handles notification-
const state =
notifications: ,
;
const mutations =
setNotification(state, message, type, name )
state.notifications[name] =
message,
type,
isShown: true,
,
removeNotification(state, name)
delete state.notifications[name];
;
const actions =
async showNotification(context, options)
await context.commit('setNotification', options);
,
async removeNotification(context, name)
await context.commit('removeNotification', name);
const getters =
isNotificationShown: (state, getters) =>
return getters.getNotificationMessageList.length > 0;
,
getNotificationMessageList: state =>
return state.notifications;
,
export default
state,
actions,
mutations,
getters,
And this is my component-
<template>
<div v-if="isShown">
<div v-for="(notice, name, index) in notificationMessageList" :key="name">
index - notice.type - notice.message
</div>
</div>
</template>
<script>
export default
computed:
isShown()
return this.$store.getters.isNotificationShown;
,
notificationMessageList()
return this.$store.getters.getNotificationMessageList;
,
,
;
</script>
I checked with the Vue Development tool and found that the store does get updated and so does the component with the notification messages that I'm passing to the store. But the component is not being rendered. But if I use the same data by hardcoding it in the component, it works.
I'm not sure if this is the right way to connect the Vuex store to a component.
vue.js vue-component vuex vuex-modules
vue.js vue-component vuex vuex-modules
asked Mar 7 at 6:48
aravindaravind
385
385
Can you please create jsfiddle for this?
– varit05
Mar 7 at 7:56
add a comment |
Can you please create jsfiddle for this?
– varit05
Mar 7 at 7:56
Can you please create jsfiddle for this?
– varit05
Mar 7 at 7:56
Can you please create jsfiddle for this?
– varit05
Mar 7 at 7:56
add a comment |
1 Answer
1
active
oldest
votes
It's Vue reactivity problem. You need to update the reference to make Vue reactive. You can use JSON.parse(JSON.stringify())
or use ES6 syntax:
const mutations =
setNotification(state, message, type, name )
state.notifications =
...state.notifications,
[name]:
message,
type,
isShown: true
,
removeNotification(state, name)
const newNotifications = ...state.notifications
delete newNotifications[name]
state.notifications = newNotifications
;
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%2f55037644%2fiterating-over-a-vuex-store-object%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
It's Vue reactivity problem. You need to update the reference to make Vue reactive. You can use JSON.parse(JSON.stringify())
or use ES6 syntax:
const mutations =
setNotification(state, message, type, name )
state.notifications =
...state.notifications,
[name]:
message,
type,
isShown: true
,
removeNotification(state, name)
const newNotifications = ...state.notifications
delete newNotifications[name]
state.notifications = newNotifications
;
add a comment |
It's Vue reactivity problem. You need to update the reference to make Vue reactive. You can use JSON.parse(JSON.stringify())
or use ES6 syntax:
const mutations =
setNotification(state, message, type, name )
state.notifications =
...state.notifications,
[name]:
message,
type,
isShown: true
,
removeNotification(state, name)
const newNotifications = ...state.notifications
delete newNotifications[name]
state.notifications = newNotifications
;
add a comment |
It's Vue reactivity problem. You need to update the reference to make Vue reactive. You can use JSON.parse(JSON.stringify())
or use ES6 syntax:
const mutations =
setNotification(state, message, type, name )
state.notifications =
...state.notifications,
[name]:
message,
type,
isShown: true
,
removeNotification(state, name)
const newNotifications = ...state.notifications
delete newNotifications[name]
state.notifications = newNotifications
;
It's Vue reactivity problem. You need to update the reference to make Vue reactive. You can use JSON.parse(JSON.stringify())
or use ES6 syntax:
const mutations =
setNotification(state, message, type, name )
state.notifications =
...state.notifications,
[name]:
message,
type,
isShown: true
,
removeNotification(state, name)
const newNotifications = ...state.notifications
delete newNotifications[name]
state.notifications = newNotifications
;
answered Mar 7 at 8:00
ittusittus
7,1022825
7,1022825
add a comment |
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%2f55037644%2fiterating-over-a-vuex-store-object%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
Can you please create jsfiddle for this?
– varit05
Mar 7 at 7:56