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 是一套不同的技术,允许您创建可重用的定制元素(它们的 ...
随机推荐
- mysql中int型的数字怎么转换成字符串
字段:number 是integer类型 在表test中 select cast(number as char) as number from test; 或者convert()方法.因为转换 ...
- HDU2222 Keywords Search__AC自动机
Keywords Search Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u Sub ...
- springmvc框架java.lang.NoSuchMethodException问题解决
例子:https://blog.csdn.net/huaidandaidai1/article/details/81979704 原因: 在java中,如果一个类A没有自己写构造方法,那么java会自 ...
- HTML5的表单input元素的新属性
知识点 <HTML5的表单input元素的新属性>,留待学习分享... <!-- HTML5的表单input元素的新属性 Autocomplete:自动完成功能 Autofocus: ...
- Java Web学习之路
编程基础 1-1 常用数据结构 数组.链表.堆.栈.队列.Hash表.二叉树等1-2 算法思想 算法时间复杂度和空间复杂度的分析计算 1-2 算法思想:递推.递归.穷举.贪心.分治.动态规划.迭代.分 ...
- Java8新特性_四大内置核心函数式接口
Consumner : 消费型接口 Supplier :供给型接口 Function:函数式接口 Predicate:断言型接口 其他接口: 四大内置核心函数式接口: Consumner : 消费型接 ...
- 网页开发(HTML 基础)
网页的标准是W3C,目前模式是HTML.CSS和JavaScript. HTML,全称"Hyper Text Markup Language(超文本标记语言)",简单来说,网页就是 ...
- Linux提权常用漏洞速查表
漏洞列表 #CVE #Description #Kernels CVE–2018–18955 [map_write() in kernel/user_namespace.c allows privil ...
- NodeRED常用操作
NodeRED常用操作 记录使用在云服务器操作NodeRED过程中常用的一些过程或方法 重启NodeRED 通过命令行重启 我的NodeRED在pm2的自启动管理下,因此使用pm2进行重启 pm2 r ...
- linux(3) 处理目录的常用命令
目录命令总览 ls(英文全拼:list files): 列出目录及文件名 cd(英文全拼:change directory):切换目录 pwd(英文全拼:print work directory):显 ...