簡體   English   中英

在 Vue & Typescript 中定義動態組件

[英]Define dynamic component in Vue & Typescript

我有一個缺少類型檢查的簡單動態組件。 我怎樣才能進行正確的類型檢查而不是使用“任何”,這是唯一有效的方法。

<script>
...

interface {
  [key: string]: any
}

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

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

嘗試這個!

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM