No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    ssr, preFetch and store : have to go to $store._vm._data.$$state

    Help
    3
    5
    909
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      Coude last edited by

      Hello,

      I am using Quasar for ssr. I am fetching data from strapi cms (which is on the same server as quasar).

      I am using prefetch and vuex according to what I understood from the docs.

      I am seeing the data I want to see on my page BUT, as you will see below, I have to dig to " this.$store._vm._data.$$state.cms.all " to get them. Why? I do not know what I did wrong or what might be wrong. If you need any other info to answer, just ask, I would like to undestand what is wrong or what I misundestood (I am new to vuex, not too new to quasar/vue etc though) :).

      Thank you!

        preFetch ({ store, currentRoute, previousRoute, redirect, ssrContext, urlPath, publicPath }) {
          return store.dispatch('cms/getDataFromServer', {url:'http://localhost:1337/home'})
        },
      (...)
        mounted: function () {
          this.$store.registerModule('cms', cms, { preserveState: true });
          console.log(this.$store, this.$store._vm._data.$$state.cms.all);
          this.home = this.$store._vm._data.$$state.cms.all; // WHY??
        },
      

      the index store is as follow:

      import Vue from 'vue';
      import Vuex from 'vuex';
      
      import cms from './cms'
      
      Vue.use(Vuex)
      
      export default function (/* { ssrContext } */) {
        const Store = new Vuex.Store({
          modules: {
            cms
          },
      
          // enable strict mode (adds overhead!)
          // for dev mode and --debug builds only
          //strict: process.env.DEBUGGING
        })
      
        return Store
      }
      
      

      action.js

      import { axiosInstance } from '../../boot/axios.js';
      
      async function getDataFromServer ({ commit }, param) {
        return axiosInstance.get(param.url).then(({ data }) => {
          commit('create', data)
        })
      }
      
      export { getDataFromServer };
      
      beets 1 Reply Last reply Reply Quote 0
      • beets
        beets @Coude last edited by beets

        @Coude This sounds strange, I’ll start by asking that you’ve tried

            this.home = this.$store.state.cms.all;
        

        Edit: also, you could try making a getter, and using

            this.home = this.$store.getters['cms/someGetterMethod']
        
        1 Reply Last reply Reply Quote 0
        • C
          Coude last edited by

          @beets
          Thank you for your answer. Of course I’ve tried this.home = this.$store.state.cms.all; 🙂 (That’s why I have those console.log, because I tried to find if it was hidden somewhere, and it was!).

          And, that’s what I thought about during sleep : I did not make a getter.

          metalsadman 1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman @Coude last edited by

            @Coude try mounted ().

            1 Reply Last reply Reply Quote 0
            • C
              Coude last edited by

              @metalsadman I just tried it, it does not change anything.
              I added getters, it works better.

              One issue I have, it’s that I am not able to lazy-register my stores. I’ve tried many many different things and I am getting hydration issue (likely due to data difference between front and ssr) and vuex namespace duplicates. So, for now, I am registering my vuex modules/stores globally in the index, it is not optimal but at least it is working!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post