html fragment & html template & virtual DOM & web components
html fragment & html template & virtual DOM
https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template

Fragment
const dom = document.querySelector('#list');
const fruits = ['Apple', 'Orange', 'Banana', 'Melon'];
const fragment = new DocumentFragment()
fruits.forEach(function (fruit) {
let li = document.createElement('li');
li.innerHTML = fruit;
fragment.appendChild(li);
})
dom.appendChild(fragment);
template
// Test to see if the browser supports the HTML template element by checking
// for the presence of the template element's content attribute.
if ('content' in document.createElement('template')) {
// Instantiate the table with the existing HTML tbody
// and the row with the template
const template = document.querySelector('#productrow');
// Clone the new row and insert it into the table
let tbody = document.querySelector("tbody");
let clone = document.importNode(template.content, true);
let td = clone.querySelectorAll("td");
td[0].textContent = "1235646565";
td[1].textContent = "Stuff";
tbody.appendChild(clone);
// Clone the new row and insert it into the table
let clone2 = document.importNode(template.content, true);
td = clone2.querySelectorAll("td");
td[0].textContent = "0384928528";
td[1].textContent = "Acme Kidney Beans 2";
tbody.appendChild(clone2);
} else {
// Find another way to add the rows to the table because
// the HTML template element is not supported.
}
slot
web components
https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots
web components
custom element
https://developer.mozilla.org/en-US/docs/Web/Web_Components
refs
html fragment & html template & virtual DOM
https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template

Fragment
const dom = document.querySelector('#list');
const fruits = ['Apple', 'Orange', 'Banana', 'Melon'];
const fragment = new DocumentFragment()
fruits.forEach(function (fruit) {
let li = document.createElement('li');
li.innerHTML = fruit;
fragment.appendChild(li);
})
dom.appendChild(fragment);
template
// Test to see if the browser supports the HTML template element by checking
// for the presence of the template element's content attribute.
if ('content' in document.createElement('template')) {
// Instantiate the table with the existing HTML tbody
// and the row with the template
const template = document.querySelector('#productrow');
// Clone the new row and insert it into the table
let tbody = document.querySelector("tbody");
let clone = document.importNode(template.content, true);
let td = clone.querySelectorAll("td");
td[0].textContent = "1235646565";
td[1].textContent = "Stuff";
tbody.appendChild(clone);
// Clone the new row and insert it into the table
let clone2 = document.importNode(template.content, true);
td = clone2.querySelectorAll("td");
td[0].textContent = "0384928528";
td[1].textContent = "Acme Kidney Beans 2";
tbody.appendChild(clone2);
} else {
// Find another way to add the rows to the table because
// the HTML template element is not supported.
}
slot
web components
https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_templates_and_slots
web components
custom element
https://developer.mozilla.org/en-US/docs/Web/Web_Components
refs
html fragment
html template
virtual DOM
web components
html, fragment, template, virtual DOM, js, svg, HTML5, slot, web components
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
html fragment & html template & virtual DOM & web components的更多相关文章
- 前端未来趋势之原生API:Web Components
声明:未经允许,不得转载. Web Components 现世很久了,所以你可能听说过,甚至学习过,非常了解了.但是没关系,可以再重温一下,温故知新. 浏览器原生能力越来越强. js 曾经的 JQue ...
- Web Components All In One
Web Components All In One Web Components https://www.webcomponents.org/ HTML Template Custom Element ...
- 【shadow dom入UI】web components思想如何应用于实际项目
回顾 经过昨天的优化处理([前端优化之拆分CSS]前端三剑客的分分合合),我们在UI一块做了几个关键动作: ① CSS入UI ② CSS作为组件的一个节点而存在,并且会被“格式化”,即选择器带id前缀 ...
- Web Components & HTML template & HTML slot
Web Components & HTML template & HTML slot https://github.com/xgqfrms/es-next/issues/2 live ...
- Web Components & HTML5 & template & slot
Web Components & HTML5 & template & slot https://developer.mozilla.org/en-US/docs/Web/HT ...
- Web Components初探
本文来自 mweb.baidu.com 做最好的无线WEB研发团队 是随着 Web 应用不断丰富,过度分离的设计也会带来可重用性上的问题.于是各家显神通,各种 UI 组件工具库层出不穷,煞有八仙过海之 ...
- The state of Web Components
Web Components have been on developers’ radars for quite some time now. They were first introduced b ...
- 前端应该知道的Web Components
前端组件化的痛点 在前端组件化横行的今天,确实极大的提升了开发效率.不过有一个问题不得不被重视,拟引入的这些html.css.js代码有可能对你的其他代码造成影响. 虽然我们可以通过命名空间.闭包等一 ...
- 一个使用 Web Components 的音乐播放器: MelodyPlayer
先上效果预览: Web Components 首先,什么是 Web Components ? MDN 给出的定义是: Web Components 是一套不同的技术,允许您创建可重用的定制元素(它们的 ...
随机推荐
- Python学习【第7篇】:字符串拼接
1.格式化字符有%s,%d,%f浮点数 %s代表格式化字符串,s是string意思 msg = 'my name is %s'%"xiaoxing"print(msg)运行结果:m ...
- 济南学习D1T5__HEAP
死亡 [问题描述] 现在有个位置可以打sif,有个人在排队等着打sif.现在告诉你前个人每个人需要多长的时间打sif,问你第个人什么时候才能打sif.(前个人必须按照顺序来) [输入格式] 第一行两个 ...
- BGP( Border Gateway Protocol)---边界网关协议
摘自: https://blog.csdn.net/weixin_43751619/article/details/84954755 一,BGP协议原理与配置 边界网关协议( Border Gatew ...
- python——模块、标准库、第三方模块安装
模块(module)简介 模块化--指将一个完整的程序分解为一个一个小的模块,通过将模块组合,来搭建出一个完整的程序. 模块化的特点: ① 方便开发 ② 方便维护 ③ 模块可以复用! 在Python中 ...
- 小心 Enum Parse 中的坑
小心 Enum Parse 中的坑 Intro 最近使用枚举的时候,踩了一个小坑,分享一下,主要是枚举从 int 值转成枚举时可能会遇到 Sample 来看下面的示例: 首先定义一个枚举: publi ...
- MySQL数据库迁移与MySQL数据库批量恢复
目录 一.MySQL数据库迁移或备份 1. 了解使用InnoDB引擎创建数据库所产生的文件 2. 迁移数据库步骤 1. 从A服务器迁移至B服务器 2. MySQL重装并导入之前数据库 二.MySQL数 ...
- HBase和ElasticSearch索引类型及存储位置
本篇博文主要对HyperBase(HBase).Search(ElasticSearch)的索引类型及具体存储位置进行概要总结,让大家从整体上了解TDH平台中HyperBase和Search索引的管理 ...
- 通过SignalR技术整合即时通讯(IM)在.NET中应用落地
1.引言 即时通讯(IM)是RDIFramework.NET敏捷开发框架全新提供的一个基于Web的即时通讯.内部聊天沟通的工具.界面美观大方对于框架内部进行消息的沟通非常方便.基于RDIFramewo ...
- B - B(Is It A Tree?)
给出一堆边给你,让你判断这是不是一棵树.边的信息以(start , end)的形式给出. A tree is a well-known data structure that is either em ...
- B. Modular Equations
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. L ...