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

            Can't find variable: document ReactNative Js2019 Community Moderator ElectionReactNative: how to center text?Can't find variable: navigate - ReactNative navigationReact Native error: “Can't find variable: TouchableHighlight”How to use Expo.DocumentPicker.getDocumentAsync properly. [Expo] [ReactNative]Can't find variable: regeneratorRuntime (ReactNative)Reactnative Expo It is advisable for a StartUp?Can't find variable : Self / Can't install firebaseNPM Install Error in installing ReactNative CLIContacts Displaying in App using ReactnativeFacebook login error: can't find variable: Alert

            Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices