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

    Choosing different layout vue files depending on platform

    Help
    4
    7
    973
    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.
    • O
      OrthoCube last edited by Shone

      I would like to use different vue layout files depending on the platform used (desktop / mobile). I thought it might be possible by modifying routes.

      component: () => {
          this.$q.platform.is.mobile ? import('layouts/MobileLayout.vue') : import('layouts/DesktopLayout.vue')
      }
      

      but it seems that $q is not accessible from the this instance from the routes. I was thinking that it’d be as simple as this but it seems it isn’t.

      In the end, do I just have to use a single layout and just use v-if all over to choose what to display?

      I found a post on this forum that is asking the same thing, and the answer just says that “you can use multiple layouts, you are not limited to using just one” which is true, if the path determines which layout to use (for example, www.mysite.com/mobile/posts compared to www.mysite.com/posts) but how do I use the same path but choose which layout to use depending on platform?

      Thanks in advance.

      1 Reply Last reply Reply Quote 0
      • rstoenescu
        rstoenescu Admin last edited by

        You’re using ES6 arrow function, so it’s natural “this” does not refer to the same thing as a normal function. So use normal function.

        O 1 Reply Last reply Reply Quote 1
        • O
          OrthoCube @rstoenescu last edited by OrthoCube

          @rstoenescu Unfortunately, it seems that this is undefined even when using normal functions.

          component: function () {
            return this.$q.platform.is.mobile ? import('layouts/MobileLayout.vue') : import('layouts/DesktopLayout.vue')
          },
          E 1 Reply Last reply Reply Quote 0
          • rstoenescu
            rstoenescu Admin last edited by

            Are you on SSR or what build mode are you using? Need more details in order to help you.

            1 Reply Last reply Reply Quote 0
            • E
              eason @OrthoCube last edited by

              @orthocube

              Maybe like this
              `
              import { Platform } from ‘quasar’

              component: () => {
              return Platform.is.mobile ? import(‘layouts/MobileLayout.vue’) : import(‘layouts/DesktopLayout.vue’)
              }
              `

              1 Reply Last reply Reply Quote 0
              • G
                genyded last edited by

                Make the layout a Vue dynamic component then switch it based on the platform.

                1 Reply Last reply Reply Quote 0
                • O
                  OrthoCube last edited by

                  @rstoenescu This is just the default SPA. this in the routes.js file does not seem to point to Vue’s this so I can’t access $q. I have found a way, by using one layout but with a couple of v-ifs, choosing which to display based on the platform, but maybe there’s a better way to this… I just thought.

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