how to delete the virtual dom that created in memory using js

const virtualDomConvert = (filename = ``) => {
const svg = document.querySelector(`[id="live_map_svg"]`);
const clone = svg.cloneNode(true);
clone.id = 'vdom_svg';
// autoRemoveAttributes(clone);
const html = clone.outerHTML;
// add xml namespace, support browser open preview
const xml = `
<?xml version="1.0" encoding="UTF-8"?>
${html}
`.trim();
const alink = document.createElement('a');
alink.setAttribute('href', 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(xml));
alink.setAttribute('download', filename);
alink.style.display = 'none';
const vdom = document.createElement(`div`);
vdom.appendChild(alink);
alink.click();
vdom.removeChild(alink);
// ??? how to delete vdom ???
// document.body.appendChild(alink);
// alink.click();
// document.body.removeChild(alink);
}

solution

object delete


vdom = document.createElement(`div`);
// <div>​</div>​ vdom.remove();
// undefined vdom;
// <div>​</div>​ window.vdom;
// <div>​</div>​ this.vdom;
// <div>​</div>​
delete this.vdom;
// true
vdom;
// VM98286:1 Uncaught ReferenceError: vdom is not defined at <anonymous>:1:1

vdom = document.createElement(`div`);
// <div>​</div>​ vdom.setAttribute("id", "uuid_div");
//undefined
document.getElementById("uuid_div");
//null
document.getElementById("uuid_div").remove();
//VM105598:1 Uncaught TypeError: Cannot read property 'remove' of null
at <anonymous>:1:36

demo




not work

https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild

// remove child
node.removeChild(child);
// OR
const oldChild = node.removeChild(child);

https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove

// remove self
node.remove();

Web Component

https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement#Web_component_example

https://developer.mozilla.org/en-US/docs/Web/API/HTMLUListElement

https://www.w3.org/TR/custom-elements/

https://github.com/w3c/webcomponents/

refs

https://www.digitalocean.com/community/tutorials/how-to-make-changes-to-the-dom



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


how to delete the virtual dom that created in memory using js的更多相关文章

  1. React v16-alpha 从virtual dom 到 dom 源码简读

    一.物料准备 1.克隆react源码, github 地址:https://github.com/facebook/react.git 2.安装gulp 3.在react源码根目录下: $npm in ...

  2. Virtual DOM(八)

    Virtual DOM 这个概念相信大部分人都不会陌生,它产生的前提是浏览器中的 DOM 是很“昂贵"的,为了更直观的感受,我们可以简单的把一个简单的 div 元素的属性都打印出来,如图所示 ...

  3. vue的Virtual Dom实现- snabbdom解密

    vue在官方文档中提到与react的渲染性能对比中,因为其使用了snabbdom而有更优异的性能. JavaScript 开销直接与求算必要 DOM 操作的机制相关.尽管 Vue 和 React 都使 ...

  4. 将你的 Virtual dom 渲染成 Canvas

    项目概述 一个基于Vue的virtual dom插件库,按照Vue render 函数的写法,直接将Vue生成的Vnode渲染到canvas中.支持常规的滚动操作和一些基础的元素事件绑定. githu ...

  5. 简单说明 Virtual DOM 为啥快

    Virtual DOM 就是用 JS 的对象来描述 DOM 结构的一个 DOM 树.如: var element = { tagName: 'ul', // 节点标签名 props: { // DOM ...

  6. virtual DOM的作用:将DOM的维护工作由系统维护转交给virtual DOM维护

    virtual DOM的作用:将DOM的维护工作由系统维护转交给virtual DOM维护 两个方面:对应用端 & 对DOM端(渲染准备的计算) 1.将DOM状态的维护工作由系统维护转交给vi ...

  7. React Virtual DOM Explained in Simple English

    If you are using React or learning React, you must have heard of the term “Virtual DOM”. Now what is ...

  8. React virtual DOM explained in simple English/简单语言解释React的虚拟DOM

    初学React,其中一个很重要的概念是虚拟DOM,看了一篇文章,顺带翻译一下. If you are using React or learning React, you must have hear ...

  9. 窥探Vue.js 2.0 - Virtual DOM到底是个什么鬼?

    引言 你可能听说在Vue.js 2.0已经发布,并且在其中新添加如了一些新功能.其中一个功能就是"Virtual DOM". Virtual DOM是什么 在之前,React和Em ...

随机推荐

  1. Spring 设计模式介绍

    JDK 中用到了那些设计模式?Spring 中用到了那些设计模式?这两个问题,在面试中比较常见.我在网上搜索了一下关于 Spring 中设计模式的讲解几乎都是千篇一律,而且大部分都年代久远.所以,花了 ...

  2. Redis分布式锁升级版RedLock及SpringBoot实现

    分布式锁概览 在多线程的环境下,为了保证一个代码块在同一时间只能由一个线程访问,Java中我们一般可以使用synchronized语法和ReetrantLock去保证,这实际上是本地锁的方式.但是现在 ...

  3. logstash的S3 input插件

    logstash从AWS S3获取日志信息的常用方法有两种,一种是利用AWS lambda,另一种就是利用logstash的S3 input插件. 插件github:https://github.co ...

  4. zabbix管理员设置

    1.认证 2.用户组和用户

  5. 如何用RabbitMQ实现延迟队列

    前言 在 jdk 的 juc 工具包中,提供了一种延迟队列 DelayQueue.延迟队列用处非常广泛,比如我们最常见的场景就是在网购或者外卖平台中发起一个订单,如果不付款,一般 15 分钟后就会被关 ...

  6. Java中详述线程间协作

    线程协作 首先引入一段代码: package 线程间数据共享; import java.util.Date; public class Watch { private static String ti ...

  7. 一文入门Linux下gdb调试(一)

    作者:良知犹存 转载授权以及围观:欢迎添加微信号:Conscience_Remains 总述 在window下我们习惯了IDE的各种调试按钮,说实话确实挺方便的,但到了Linux下,没有那么多的IDE ...

  8. BZOJ1396 识别子串【SAM+SegmentTree】

    BZOJ1396 识别子串 给定一个串\(s\),对于串中的每个位置,输出经过这个位置且只在\(s\)中出现一次的子串的最短长度 朴素的想法是,我们要找到那些只出现一次的子串,之后遍历每个串,把串所覆 ...

  9. NOIP2015提高组 信息传递 ---并查集问题

    题目描述 有 n 个同学(编号为 1 到 n )正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为 i 的同学的信息传递对象是编号为 Ti​ 的同学. 游戏开始时,每人都只 ...

  10. poj 2653 线段相交裸题(解题报告)

    #include<stdio.h> #include<math.h> const double eps=1e-8; int n; int cmp(double x) { if( ...