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

    Wait for async data in boot file

    Help
    2
    8
    33
    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.
    • S
      steenole last edited by

      I have a single-page application which needs to get some configuration data from a json file, before the application can start. Things like api root and oauth configuration. This is needed because the same app runs on different environments, but with different configs.
      In order to read the config file, I make an ajax fetch. But since this is asynchronous, the app starts before my data is ready.
      How can I make my app wait for the config data, before it starts?

      1 Reply Last reply Reply Quote 0
      • S
        steenole last edited by

        In plain Vue, I would do something like this, in mains.js, to defer the Vue instantiation.
        But Quasar does not give me access to modify main.js

        fetch(’/config.json’).then(res => res.json()).then(config => {
        new Vue({
        data(){
        return config
        },
        render: h => h(app)
        }).mount(’#app’)
        })

        dobbel 1 Reply Last reply Reply Quote 0
        • dobbel
          dobbel @steenole last edited by

          @steenole

          See:
          https://quasar.dev/quasar-cli/boot-files

          1 Reply Last reply Reply Quote 0
          • S
            steenole last edited by

            I am aware of boot files.
            In a boot file, I can start fetching the config data, but I can’t wait for the response, so my app will continue starting up, before my config data are ready.

            1 Reply Last reply Reply Quote 0
            • dobbel
              dobbel last edited by dobbel

              @steenole

              See this thread how to in a boot file:
              https://forum.quasar-framework.org/topic/5929/timing-async-problem-with-vue-router-guard-and-loaded-user-roles-using-axios-while-starting-the-app-for-the-first-time/8?_=1615367296421

              1 Reply Last reply Reply Quote 0
              • S
                steenole last edited by

                Thank you @dobbel
                I had missed the impact of using an async boot function. That did the trick.

                dobbel 2 Replies Last reply Reply Quote 0
                • dobbel
                  dobbel @steenole last edited by

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • dobbel
                    dobbel @steenole last edited by

                    @steenole

                    Good to know that ‘trick’ works!

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