简体   繁体   English

在 Vue & Typescript 中定义动态组件

[英]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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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