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

    QDialog with custom Component dynamically imported

    Help
    2
    3
    1128
    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.
    • B
      BL3 last edited by BL3

      Hi im running into a problem with QDialog when i try to import the custom component dynamically.

      <q-dialog ref="customDialog" @hide="onDialogHide">...</q-dialog>
      

      this code works fine…

      import CustomDialog from (./CustomDialog)
      ...
      methods: {
          openDialog () {
            this.$q.dialog({
              component: CustomDialog, 
              parent: this
            })
          }
        }
      

      but on dynamically importing the custom component it fails

      methods: {
          openDialog () {
            this.$q.dialog({
              component: () => import('./CustomDialog'),
              parent: this
            })
          }
        }
      

      with the error TypeError: “this.$refs.dialog is undefined”

      Any hint is appreciated 🙂

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

        @BL3 you probably need to wrap the second inside a nextTick or try await for your dialog call. or do local example from vue docs https://vuejs.org/v2/guide/components-dynamic-async.html.

        ...
        components: {
          CustomDialog: () => import('./CustomDialog')
        }
        ...
        this.$q.dialog({
                component: CustomDialog,
                parent: this
              })
        ...
        
        
        B 1 Reply Last reply Reply Quote 0
        • B
          BL3 @metalsadman last edited by

          @metalsadman thanks for your hint to use async await, this did the job 🙂

          methods: {
              async openDialog () {
                const CustomDialog = await import (./CustomDialog)
                this.$q.dialog({
                  component: CustomDialog,
                  parent: this
                })
              }
            }
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post