web-component - 在 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
对我来说是更明显的专有名称)。
如果没有,最佳做法是什么?
解决方案
title
是一个全局 html 属性名称 - 'reserved'。请参阅https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes。作为最佳实践,您不应为 @Props 使用全局属性名称。我不知道任何命名属性的“标准”,它是组件的标题,但与全局标题属性(通常用于工具提示)不同。
推荐阅读
- java - Grails 应用程序未启动
- r - tm_polygons border.col 应该由另一个使用 tmap 包的变量定义
- vaadin - Vaadin 图表未使用正确的宽度
- c# - c#蓝牙SerialPort重新连接
- mysql - 可以更新集字段替换多个文件
- javascript - 为什么 window.getComputedStyle(element).getPropertyValue("order") 不返回 flexbox 元素的顺序?
- session - 试剂会话未持续
- php - 停止价值 0 美元产品的 WooCommerce 订阅管理员续订通知
- amazon-web-services - 如何将文件从 EC2 复制到本地机器?
- file - Spotify 如何在后端存储音乐文件?