Vuex not returning expected state

I have a pop up modal that should appear if the user has no transactions. depositHistory is an array with these transactions. If its length is greater than 0, the pop up should remain hidden. If its length is equal to 0, the pop up should render.

The user account I’m using has 2 transactions. The pop up shouldn’t show but it does. The console.log() returns an empty array which is not correct. I have another component someone else wrote which uses depositHistory in the same way and is working as expected.

Component:

<template>
  <div v-if='renderModal'>
    <p>Fund your account</p>
  </div>
</template>

<script>
const DepositGetter = namespace("deposit").Getter

const AppProps = Vue.extend({
data: () => {
  return {
    renderModal: false
  }
},
beforeMount() {
  // renders modal if user has no transactions
  if (this.depositHistory.length === 0) this.renderModal = true

  console.log(JSON.parse(JSON.stringify(this.depositHistory)))
  // usually returns [__ob__: Observer]
  // added JSON methods so now it logs []
}

export default class HomeGameBanner extends AppProps {
  @DepositGetter depositHistory
}
</script>

I don’t think you need this but just in case.

Store:

type DepositGetter = GetterTree<DepositState, RootState>;

export const getters: DepositGetter = {
  depositHistory: state => state.content
};

export const deposit: Module<DepositState, RootState> = {
  getters
}

185 thoughts on “Vuex not returning expected state”

  1. An impressive share! I have just forwarded this onto a
    friend who was conducting a little homework on this.
    And he in fact bought me breakfast due to the fact that I stumbled upon it for him…

    lol. So allow me to reword this…. Thank YOU for the meal!!
    But yeah, thanks for spending time to talk about this issue here on your web site.

    Reply
  2. I like the valuable info you supply in your articles.
    I’ll bookmark your blog and take a look at again here regularly.
    I’m slightly certain I’ll be told many new stuff right right here!

    Best of luck for the next!

    Reply
  3. This design is spectacular! You obviously know how to
    keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well,
    almost…HaHa!) Excellent job. I really loved what you had
    to say, and more than that, how you presented it.

    Too cool!

    Reply
  4. When I initially commented I clicked the “Notify me when new comments are added”
    checkbox and now each time a comment is added
    I get three e-mails with the same comment. Is there any way you can remove people from that service?
    Thanks a lot!

    Reply
  5. I absolutely love your blog and find a lot of your
    post’s to be exactly what I’m looking for. Does one
    offer guest writers to write content for you? I wouldn’t mind composing a post or elaborating on most of
    the subjects you write concerning here. Again, awesome blog!
    quest bars http://j.mp/3C2tkMR quest bars

    Reply
  6. Great beat ! I wish to apprentice while you amend your site, how could i subscribe
    for a blog web site? The account helped me a acceptable deal.
    I had been a little bit acquainted of this your broadcast
    offered bright clear concept

    Reply

Leave a Comment