简体   繁体   中英

How define type of ref method in Quasar Framework with Vue3 and Typescript

  • Quasar Framework v2 Beta
  • Vue 3 Composition Api
  • Typescript

component template

<q-btn 
  @click.stop="showingActionMenu()" 
  color="grey-7" 
  round 
  flat 
  icon="more_vert"
>
  <q-menu
    ref="showAction"
    auto-close
  >
    ...                       
  </q-menu>
</q-btn>
setup() {
  ...
  const showAction = ref<Function | null>(null)
  ...
})

component setup

return {
  ...
  showAction,
  showingActionMenu() {
    showAction?.value?.show()
  },
  ...
}

returned method shows error

Property 'show' does not exist on type 'Function'.

The type of the ref should be QMenu which is imported from quasar framework:

import { QMenu } from 'quasar'
...
setup() {
  ...
  const showAction = ref<QMenu| null>(null)
  ...
  return {
    ...
    showAction,
    showingActionMenu() {
      showAction.value?.show()
    },
    ...
  }
}

LIVE DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM