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

    tab-route and pages issue when switching tab

    Help
    3
    4
    1246
    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
      Oxar last edited by Oxar

      Hi. I have created a simple app with route tabs. Each route links to a page (pgGeneral and pgCriteria). I have set this up as advised in the guide notes.
      I have encountered an issue when I switch tab: data entered on pgGeneral get removed when going to the next tab criteria. Is this normal behaviour? If not, how would I get to keep my data? by using vuex?
      Thanks.

      Below is my setup:
      layout: default.vue

          <q-layout-header>
            <q-toolbar
              color="primary"
              :glossy="$q.theme === 'mat'"
              :inverted="$q.theme === 'ios'"
            >
              <q-toolbar-title>
               App
                <div slot="subtitle">Running on Quasar v{{ $q.version }}</div>
              </q-toolbar-title>
            </q-toolbar>
          <q-tabs>
            <q-route-tab slot="title" name="tab-1" icon="subject" label="Generalities" to="/" exact />
            <q-route-tab slot="title" name="tab-2" icon="fingerprint" label="Inclusion Criteria" to="/criteria" exact />
          </q-tabs>
          </q-layout-header>
          <q-page-container>
            <router-view />
          </q-page-container>
      

      router --> routes.js:

      export default [
        {
          path: '/',
          component: () => import('layouts/default'),
          children: [
            { path: '', component: () => import('pages/pgGeneral') },
            { path: 'criteria', component: () => import('pages/pgCriteria') }
          ]
        },
      
        { // Always leave this as last one
          path: '*',
          component: () => import('pages/404')
        }
      ]
      

      my pgGeneral is:

      <template>
        <q-page>
          <!-- General Information Tab Card -->
          <q-card class="bg-cyan-2 q-ma-xl">
            <q-card-main>
              <q-field label="Title" >
               <q-input v-model="studyTitle" clearable />
                </div>
              </q-field>
            </q-card-main>
          </q-card> 
        </q-page>
      </template>
      
      <script>
      export default {
        data () {
          return {
            studyTitle: ''
          }
        }
      }
      </script>
      
      <style>
      </style>
      
      
      1 Reply Last reply Reply Quote 0
      • G
        genyded last edited by genyded

        Whether or not you persist the data in Vuex… you will need to load it (typically in the created method) in the component that the tab loads. It’s no different than if you took the tabs out of the mix and just navigated between the pages. An alternative would be Vue’s dynamic components which can be wrapped in a keep-alive element.

        1 Reply Last reply Reply Quote 2
        • Hawkeye64
          Hawkeye64 last edited by

          Exactly what @genyded said…

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

            Thanks @genyded. I am also experimenting with the keep-alive element.

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