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的更多相关文章

  1. 前端未来趋势之原生API:Web Components

    声明:未经允许,不得转载. Web Components 现世很久了,所以你可能听说过,甚至学习过,非常了解了.但是没关系,可以再重温一下,温故知新. 浏览器原生能力越来越强. js 曾经的 JQue ...

  2. Web Components All In One

    Web Components All In One Web Components https://www.webcomponents.org/ HTML Template Custom Element ...

  3. 【shadow dom入UI】web components思想如何应用于实际项目

    回顾 经过昨天的优化处理([前端优化之拆分CSS]前端三剑客的分分合合),我们在UI一块做了几个关键动作: ① CSS入UI ② CSS作为组件的一个节点而存在,并且会被“格式化”,即选择器带id前缀 ...

  4. Web Components & HTML template & HTML slot

    Web Components & HTML template & HTML slot https://github.com/xgqfrms/es-next/issues/2 live ...

  5. Web Components & HTML5 & template & slot

    Web Components & HTML5 & template & slot https://developer.mozilla.org/en-US/docs/Web/HT ...

  6. Web Components初探

    本文来自 mweb.baidu.com 做最好的无线WEB研发团队 是随着 Web 应用不断丰富,过度分离的设计也会带来可重用性上的问题.于是各家显神通,各种 UI 组件工具库层出不穷,煞有八仙过海之 ...

  7. The state of Web Components

    Web Components have been on developers’ radars for quite some time now. They were first introduced b ...

  8. 前端应该知道的Web Components

    前端组件化的痛点 在前端组件化横行的今天,确实极大的提升了开发效率.不过有一个问题不得不被重视,拟引入的这些html.css.js代码有可能对你的其他代码造成影响. 虽然我们可以通过命名空间.闭包等一 ...

  9. 一个使用 Web Components 的音乐播放器: MelodyPlayer

    先上效果预览: Web Components 首先,什么是 Web Components ? MDN 给出的定义是: Web Components 是一套不同的技术,允许您创建可重用的定制元素(它们的 ...

随机推荐

  1. css知识补充

    盒子模型的介绍: 在网页中基本上都会显示一些方方正正的盒子,这种盒子就被我们称为盒模型 盒子模型的五个属性: width,height,border(边框),padding(内边距),margin(外 ...

  2. python3编码转换

    str->bytes:encode编码 bytes->str:decode解码 字符串通过编码成为字节码,字节码通过解码成为字符串. >>> text = '我是文本' ...

  3. C#9.0:Records

    概述 在C#9.0下,record是一个关键字,微软官方目前暂时将它翻译为记录类型. 传统面向对象的编程的核心思想是一个对象有着唯一标识,封装着随时可变的状态.C#也是一直这样设计和工作的.但是一些时 ...

  4. Spring Boot构建 RESTful 风格应用

    Spring Boot构建 RESTful 风格应用 1.Spring Boot构建 RESTful 风格应用 1.1 实战 1.1.1 创建工程 1.1.2 构建实体类 1.1.4 查询定制 1.1 ...

  5. 关于webservice实现web接口

    package service; import java.util.List; import javax.jws.WebMethod;import javax.jws.WebService; /** ...

  6. (13)Linux文件系统的优缺点

    通过文件系统的方式来组织磁盘存储和数据管理.有以下几个方面的好处. 数据的读取.管理操作变得简单 文件系统给用户提供了一个简单的操作界面,用户可以通过对文件系统的简单操作,实现对磁盘的管理.虽然 Li ...

  7. Java编程工具IDEA的使用

    IDEA psvm + Enter 快速构建main方法 sout + Enter 快速打印与句 Ctrl+Shift + Enter,语句完成 Ctrl+F12,可以显示当前文件的结构 Ctrl + ...

  8. mitmproxy使用详解

    mitmproxy 相比Charles.fiddler的优点在于,它可以命令行方式或脚本的方式进行mock mitmproxy不仅可以像Charles那样抓包,还可以对请求数据进行二次开发,进入高度二 ...

  9. Codeforces Round #652 (Div. 2)D. TediousLee 推导

    题意: Rooted Dead Bush (RDB) of level 1是只有一个点,如下图 当(RDB) of level i变成(RDB) of level i+1的时候,每一个顶点要进行下面的 ...

  10. Codeforces Round #531 (Div. 3) D. Balanced Ternary String (贪心)

    题意:给你一个长度为\(3*n\)的字符串,要求修改最少的次数,使得字符串中\(0,1,2\)的个数相同,并且在最少次数的情况下使字典序最小. 题解:贪心,\(0\)一定放在前面,\(1\)和\(2\ ...