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

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page