使用合成API和打字稿打字系统对Vue组件进行严格打字道具

问题描述 投票:1回答:1

我正在使用带有打字稿的vue composition api。

如何使用打字稿打字系统强烈打字道具道具?

typescript vue.js strong-typing vue-composition-api
1个回答
0
投票

如官方docs中所述,您可以通过两种方式输入道具:

通过参数注释定义农作物

import { defineComponent } from 'vue'

export default defineComponent((props: { foo: string }) => {
  props.foo
})

或类似这样

import { defineComponent } from 'vue'

export default defineComponent({
  props: {
    foo: String
  },
  setup(props) {
    props.foo // <- type: string
  }
})
© www.soinside.com 2019 - 2024. All rights reserved.