首页 > 解决方案 > 在 Web 组件中不使用保留的公共名称的正确方法是什么

问题描述

当我使用模板运行构建时,我得到

[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对我来说是更明显的专有名称)。
如果没有,最佳做法是什么?

标签: web-componentstenciljs

解决方案


title是一个全局 html 属性名称 - 'reserved'。请参阅https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes。作为最佳实践,您不应为 @Props 使用全局属性名称。我不知道任何命名属性的“标准”,它是组件的标题,但与全局标题属性(通常用于工具提示)不同。


推荐阅读