简体   繁体   中英

Define dynamic component in Vue & Typescript

I have a simple dynamic component which is missing type checking. How can I do proper type checking instead of using 'any', which is the only thing that worked.

<script>
...

interface {
  [key: string]: any
}

const pages: page = {
  Intro,
  Play,
  End,
}
</script>

<template>
  <component :is="pages[state.page]" />
</template>

Try this!

interface page {
  Intro: VueComponent;
  Play: VueComponent;
  End: VueComponent;
}

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