当我使用模具运行一个构建时,我会得到
[Warn]
The @Prop() name "title" is a reserved public name. Please rename the "title"
prop so it does not conflict with an existing standardized prototype member.
Reusing prop names that are already defined on the element's prototype may
cause unexpected runtime errors or user-interface issues on various browsers,
so it's best to avoid them entirely.我知道这只是一个警告,但由于它可能会导致意外的运行时错误,我想知道是否已经存在命名它的标准。(因为对我来说,title是一个比较合适的名字)。
如果没有,最佳做法是什么?
发布于 2021-03-14 15:51:26
到今天为止,我找到的唯一解决办法是添加attributes作为属性,并通过这个变量传递所有信息,如下所示
attributes: {
title: string
description: string
/** ... */
}我找不到比这更好的了。
但我对任何想法都持开放态度
发布于 2019-09-03 20:33:46
title是一个全局html属性名-“保留”。见attributes。作为一种最佳实践,您不应该为@Props使用全局属性名。我不知道任何命名属性的“标准”,该属性是组件的标题,但与全局title属性(通常用于工具提示)不一样。
发布于 2022-05-21 19:32:17
属性和组件属性是强连接的,但不一定是相同的。由于HTMLElement支持类型,我们不能使用标题变量,但可以将字段文本设置为标题,如下所示
@Prop({ attribute: 'title' }) heading?: string;https://stackoverflow.com/questions/57675138
复制相似问题