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










2















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.










share|improve this question






















  • Can you please create jsfiddle for this?

    – varit05
    Mar 7 at 7:56















2















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.










share|improve this question






















  • Can you please create jsfiddle for this?

    – varit05
    Mar 7 at 7:56













2












2








2








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 6:48









aravindaravind

385




385












  • 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





Can you please create jsfiddle for this?

– varit05
Mar 7 at 7:56












1 Answer
1






active

oldest

votes


















1














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

;





share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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

    ;





    share|improve this answer



























      1














      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

      ;





      share|improve this answer

























        1












        1








        1







        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

        ;





        share|improve this answer













        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

        ;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 8:00









        ittusittus

        7,1022825




        7,1022825





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme