1

根据旧函数 rfc,Vue3 将支持 typescript only props -typing:https ://github.com/vuejs/rfcs/blob/function-apis/active-rfcs/0000-function-api.md#typescript-only-道具打字

当我尝试遵循代码时,它似乎不起作用。道具将是未定义的。

interface MessageProps {
  msg: string;
  list: any[];
}
export default defineComponent({
  name: 'HelloWorld',
  setup(props: MessageProps) {
    console.log(props)
  }
})
4

1 回答 1

0

从 开始,尽管 RFC 表明它是可选的vue@3.0.0-beta.14,但该props声明仍然是必需的。我没有看到有关该特定功能的任何讨论,因此我认为它尚未实现。

同时,声明props如下所示将解决您的问题:

export default defineComponent({
  // declaration still required as of vue@3.0.0-beta.14
  props: {
    msg: String,
    list: Array,
  },
  setup(props: MessageProps) { /*...*/ }
})
于 2020-06-04T06:22:15.773 回答