【发布时间】:2022-01-28 21:36:51
【问题描述】:
给定一个定义了 props 接口 ProductProps 的组件 Product:
interface ProductProps {
name: string,
price: {
amount: number,
currency: string
}
}
如何在组件标签中为price 分配值,即我想要一些效果:
<Product name="Nice Shoes" price.amount={100} price.currency="$" />
【问题讨论】:
-
只使用一个对象字面量。
<Product name="Nice Shoes" price={{amount :100, currency:"$"}} /> -
谢谢。当我尝试类似的方法并遗漏了一套牙套时,我放弃得太快了。
标签: javascript reactjs typescript next.js react-props