Post by account_disabled on Dec 12, 2023 6:01:23 GMT
组件的批评和问题下载 PDF 格式的文章 关闭 我们都有不想做的项目。代码变得难以管理,范围不断扩大,修复后快速修复,结构在其意大利面条式代码的重量下崩溃了。创建代码可能是一件很混乱的事情。 项目受益于使用具有单一职责的简单、独立的模块。模块化代码被封装,因此无需担心实现。只要您知道模块在给定一组输入时会产生什么,您不一定需要了解它如何实现该目标。 将模块化概念应用于单一编程语言很简单,但 Web 开发需要多种技术的组合。浏览器解析HTML 、CSS 和 JavaScript 以呈现页面内容、样式和功能。 它们并不总是很容易结合,因为: 相关代码可以分成三个或更多文件,例如 全局样式和 JavaScript 对象可能会以意想不到的方式相互干扰。 除了服务器上使用的语言运行时、框架、数据库和其他依赖项遇到的问题之外,还有这些问题。 观看我们的Web 组件视频指南 什么是 Web 组件? Web 组件是一种创建可在任何页面上重用的封装的单一职责代码块的方法。 考虑 HTML 标签。给定URL,用户可以使用播放、暂停、后退、前进和调节音量等控件。 提供了样式和功能,但可以使用各种属性和 JavaScript API 调用进行更改。
任意数量的元素可以放置在其他标签内,并且它们不会发生冲突。 如果您需要自己 电话号码清单 的自定义功能怎么办?例如,一个显示页面上字数的元素?目前还没有 HTML 标签。等框架允许开发人员创建 Web 组件,其中的内容、样式和功能可以在单个 JavaScript 文件中定义。这些解决了许多复杂的编程问题,但请记住: 您需要学习如何使用该框架并随着其发展而更新您的代码。 为一个框架编写的组件很少与另一个框架兼容。 框架的受欢迎程度有起有落。您将变得依赖于开发团队和用户的突发奇想和优先事项。 标准 Web 组件可以向浏览器添加单独使用 JavaScript 难以实现的功能(例如 Shadow DOM)。 幸运的是,库和框架中引入的流行概念通常会进入 Web 标准。虽然花了一些时间,但 Web 组件已经出现了。 Web 组件简史 经过多次失败之后,Alex Russell 在 2011 年的 Fronteers 会议上首次提出了标准 Web 组件的概念。两年后, Google 的Polymer 库(基于当前提案的 polyfill)发布,但在 Chrome 和 Safari 中,第一个实现直到 2016 年才出现。 浏览器供应商花了一些时间来协商细节,但 Web 组件于 2018 年添加到 Firefox,并于 2020 年添加到 Edge(当时微软转向 Chromium 引擎)。
可以理解的是,很少有开发人员愿意或能够采用 Web 组件,但我们最终通过稳定的 API 实现了良好的浏览器支持水平。并非一切都是完美的,但它们是基于框架的组件的日益可行的替代方案。 即使您还没有准备好摆脱您最喜欢的框架,Web 组件也与每个框架兼容,并且 API 将在未来几年得到支持。 以下是每个人都可以使用的预构建 Web 组件存储库的列表组件库 通用组件 Web 组件示例 很棒的独立游戏 可访问组件 支架用户界面但是编写自己的代码更有趣! 本教程全面介绍了不使用 JavaScript 框架编写的 Web 组件。我们将解释它们是什么以及如何使它们适应您的网络项目。您将需要一些HTML5 、CSS 和 JavaScript知识。 Web 组件简介 Web 组件是自定义 HTML 元素,例如该名称必须包含连字符,以避免与 HTML 规范中正式支持的元素发生冲突。 您必须定义一个 ES2015 类来控制该元素。它可以有任何名称,但 HelloWorld 是最常见的名称之一。它必须扩展HTMLElement 接口,该接口代表每个 HTML 元素的默认属性和方法。 注意:Firefox允许您扩展特定的 HTML 元素 现在您有了一个自定义项目! CodePen演示 该组件可以像任何其他元素一样在 CSS 中设置样式 添加属性 该组件不是很有用,因为总是输出相同的文本
任意数量的元素可以放置在其他标签内,并且它们不会发生冲突。 如果您需要自己 电话号码清单 的自定义功能怎么办?例如,一个显示页面上字数的元素?目前还没有 HTML 标签。等框架允许开发人员创建 Web 组件,其中的内容、样式和功能可以在单个 JavaScript 文件中定义。这些解决了许多复杂的编程问题,但请记住: 您需要学习如何使用该框架并随着其发展而更新您的代码。 为一个框架编写的组件很少与另一个框架兼容。 框架的受欢迎程度有起有落。您将变得依赖于开发团队和用户的突发奇想和优先事项。 标准 Web 组件可以向浏览器添加单独使用 JavaScript 难以实现的功能(例如 Shadow DOM)。 幸运的是,库和框架中引入的流行概念通常会进入 Web 标准。虽然花了一些时间,但 Web 组件已经出现了。 Web 组件简史 经过多次失败之后,Alex Russell 在 2011 年的 Fronteers 会议上首次提出了标准 Web 组件的概念。两年后, Google 的Polymer 库(基于当前提案的 polyfill)发布,但在 Chrome 和 Safari 中,第一个实现直到 2016 年才出现。 浏览器供应商花了一些时间来协商细节,但 Web 组件于 2018 年添加到 Firefox,并于 2020 年添加到 Edge(当时微软转向 Chromium 引擎)。
可以理解的是,很少有开发人员愿意或能够采用 Web 组件,但我们最终通过稳定的 API 实现了良好的浏览器支持水平。并非一切都是完美的,但它们是基于框架的组件的日益可行的替代方案。 即使您还没有准备好摆脱您最喜欢的框架,Web 组件也与每个框架兼容,并且 API 将在未来几年得到支持。 以下是每个人都可以使用的预构建 Web 组件存储库的列表组件库 通用组件 Web 组件示例 很棒的独立游戏 可访问组件 支架用户界面但是编写自己的代码更有趣! 本教程全面介绍了不使用 JavaScript 框架编写的 Web 组件。我们将解释它们是什么以及如何使它们适应您的网络项目。您将需要一些HTML5 、CSS 和 JavaScript知识。 Web 组件简介 Web 组件是自定义 HTML 元素,例如该名称必须包含连字符,以避免与 HTML 规范中正式支持的元素发生冲突。 您必须定义一个 ES2015 类来控制该元素。它可以有任何名称,但 HelloWorld 是最常见的名称之一。它必须扩展HTMLElement 接口,该接口代表每个 HTML 元素的默认属性和方法。 注意:Firefox允许您扩展特定的 HTML 元素 现在您有了一个自定义项目! CodePen演示 该组件可以像任何其他元素一样在 CSS 中设置样式 添加属性 该组件不是很有用,因为总是输出相同的文本