如何用Vue3和Typescript定义Quasar Framework中ref方法的类型

ffscu2ro  于 2023-01-03  发布在  TypeScript
关注(0)|答案(1)|浏览(166)
  • 类星体框架v2 Beta
  • Vue 3组成API
  • typescript
    • 组件模板**
<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)
  ...
})
    • 组件设置**
return {
  ...
  showAction,
  showingActionMenu() {
    showAction?.value?.show()
  },
  ...
}

返回的方法显示错误

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

siotufzp1#

ref的类型应为QMenu,从类星体框架导入:

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

LIVE DEMO

相关问题