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. [JSOI2019]节日庆典 做题心得

    [JSOI2019]节日庆典 做题心得 一个性质有趣的字符串题 这要是在考场上我肯定做不出来吧 一开始还以为要 SAM 什么的暴力搞,没想到只用到了 \(Z\) 函数 -- 也是我生疏了罢 (学了啥忘 ...

  2. yum安装docker-ce-18.03.0

    yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo http://mir ...

  3. 项目Js源码整合

    整合一下目前做的项目中JS中用到的相关源码等,留待记录和使用. 一.ajaxgrid源码部分 1.初始化 2.查询 3.删除 4.保存 5.根据id获取值,时间值等 6.详情.跳转链接 : a 标签 ...

  4. Java性能优化,操作系统内核性能调优,JYM优化,Tomcat调优

    文章目录 Java性能优化 尽量在合适的场合使用单例 尽量避免随意使用静态变量 尽量避免过多过常地创建Java对象 尽量使用final修饰符 尽量使用局部变量 尽量处理好包装类型和基本类型两者的使用场 ...

  5. Redis集群搭建很easy

    前言 哨兵模式虽然让读写分离更加高可用,但单台服务器由于本身的内存和CPU瓶颈,对于高并发和大数据业务的应用场景还是远远不能满足:对于这种情况,有点经验的小伙伴会毫不犹豫的想到集群,搞他好几个节点,负 ...

  6. vue-cli3移动端自适应配置 Vant组件库

    module.exports = { presets: [ '@vue/app' ], plugins: [ ['import', { libraryName: 'vant', libraryDire ...

  7. 阅读笔记:ImageNet Classification with Deep Convolutional Neural Networks

    概要: 本文中的Alexnet神经网络在LSVRC-2010图像分类比赛中得到了第一名和第五名,将120万高分辨率的图像分到1000不同的类别中,分类结果比以往的神经网络的分类都要好.为了训练更快,使 ...

  8. Codeforces Round #613 (Div. 2) C. Fadi and LCM(LCM & GCD)

    题意: LCM(a, b) = X,求 max(a, b) 的最小值. 思路: a, b 只可能存在于 X 的因子中,枚举即可. #include <bits/stdc++.h> usin ...

  9. python的threading的使用(join方法,多线程,锁threading.Lock和threading.Condition

    一.开启多线程方法一 import threading,time def write1(): for i in range(1,5): print('1') time.sleep(1) def wri ...

  10. HDU - 1059 背包dp

    题目: 有两个小朋友想要平分一大堆糖果,但他们不知道如何平分需要你的帮助,由于没有spj我们只需回答能否平分即可. 糖果大小有6种分别是1.2.3.4.5.6,每种若干颗,现在需要知道能不能将这些糖果 ...