dom

simple MutationObserver version of DOMNodeRemovedFromDocument

 ̄綄美尐妖づ 提交于 2020-01-22 14:16:46
问题 I attach some functionality to DOM elements and want to be able to clear all references when the element is removed from the DOM so it can be garbage collected, My initial version to detect the removel of an element was this: var onremove = function(element, callback) { var destroy = function() { callback(); element.removeEventListener('DOMNodeRemovedFromDocument', destroy); }; element.addEventListener('DOMNodeRemovedFromDocument', destroy); }; Then I read that mutation events were deprecated

Vue $refs的基本用法

帅比萌擦擦* 提交于 2020-01-22 13:27:06
原文地址:http://www.cnblogs.com/xueweijie/p/6907676.html <div id="app"> <input type="text" ref="input1"/> <button @click="add">添加</button> </div> <script> new Vue({ el: "#app", methods:{ add:function(){ this.$refs.input1.value ="22"; //this.$refs.input1 减少获取dom节点的消耗 } } }) </script> 一般来讲,获取DOM元素,需document.querySelector(".input1")获取这个dom节点,然后在获取input1的值。 但是用ref绑定之后,我们就不需要在获取dom节点了,直接在上面的input上绑定input1,然后$refs里面调用就行。 然后在javascript里面这样调用:this.$refs.input1 这样就可以减少获取dom节点的消耗了 <div id="app"> <input type="text" ref="input1"/> <button @click="add">添加</button> </div> <script> new Vue({ el: "#app", methods:

vue 中的ref和$refs用法

隐身守侯 提交于 2020-01-22 13:25:57
<div id="app">    <input type="text" ref="input1"/>   <button @click="add"> 添加 </ button> </div> <script>    new Vue({     el: "#app",      methods:{       add(){         this.$refs.input1.value ="22"; //this.$refs.input1 减少获取 dom 节点的消耗       }      }    }) </script> 要点: 1.ref 被用来给元素或子组件注册引用信息。引用信息将会注册在父组件的 $refs 对象上,就比如我们想访问子组件的一些数据和方法,就可以使用ref为子组件指定一个引用的id,调用方式为 const child = parent.$refs.id 2.一般来讲,获取 DOM 元素,需 document.querySelector ( ".input1" )获取这个 dom 节点,然后在获取 input1 的值。 但是用 ref 绑定之后,我们就不需要在获取 dom 节点了,直接在上面的 input 上绑定 input1 ,然后 $refs 里面调用就行。 然后在 javascript 里面这样调用: this.$refs.input1

Vue.js中ref ($refs)用法举例总结

*爱你&永不变心* 提交于 2020-01-22 13:24:06
Vue.js中ref ($refs)用法举例总结 原文:http://www.jianshu.com/p/3bd8a2b07d57 看Vue.js文档中的ref部分,自己总结了下ref的使用方法以便后面查阅。 一、ref使用在外面的组件上 HTML 部分 <div id="ref-outside-component" v-on:click="consoleRef"> <component-father ref="outsideComponentRef"> </component-father> <p>ref在外面的组件上</p> </div> js部分 var refoutsidecomponentTem={ template:"<div class='childComp'><h5>我是子组件</h5></div>" }; var refoutsidecomponent=new Vue({ el:"#ref-outside-component", components:{ "component-father":refoutsidecomponentTem }, methods:{ consoleRef:function () { console.log(this); // #ref-outside-component vue实例 console.log(this.$refs

Vue.js中ref ($refs)用法举例总结

◇◆丶佛笑我妖孽 提交于 2020-01-22 13:22:40
原文地址:http://www.cnblogs.com/xueweijie/p/6907676.html <div id="app"> <input type="text" ref="input1"/> <button @click="add">添加</button> </div> <script> new Vue({ el: "#app", methods:{ add:function(){ this.$refs.input1.value ="22"; //this.$refs.input1 减少获取dom节点的消耗 } } }) </script> 一般来讲,获取DOM元素,需document.querySelector(".input1")获取这个dom节点,然后在获取input1的值。 但是用ref绑定之后,我们就不需要在获取dom节点了,直接在上面的input上绑定input1,然后$refs里面调用就行。 然后在javascript里面这样调用:this.$refs.input1 这样就可以减少获取dom节点的消耗了 以下内容: 作者:该帐号已被查封链接:http://www.jianshu.com/p/3bd8a2b07d57來源:简书 看Vue.js文档中的ref部分,自己总结了下ref的使用方法以便后面查阅。 一、ref使用在外面的组件上 HTML 部分 1

Angular 2 radio button events

﹥>﹥吖頭↗ 提交于 2020-01-22 13:18:32
问题 What are those events called in Angular 2 when radio button is selected or unselected. Something like <input type="radio" (select)="selected()" (unselect)="unselected()" /> So when I click one radio button in a group, it will fire selected() for the new selection and unselected() for the previous selection. 回答1: It works, <input type="radio" (change)="handleChange($event)" /> But you need code more to judge 'selected' or 'unselected'. You may try this in your *.ts file: export class Comp {

Clear element.classList

孤人 提交于 2020-01-22 13:06:32
问题 element.classList is of DOMTokenList type. Is there a method to clear this list? 回答1: I'm not aware of a "method" in the sense of a "function" associated with classList . It has .add() and .remove() methods to add or remove individual classes, but you can clear the list in the sense of removing all classes from the element like this: element.className = ""; 回答2: var classList = element.classList; while (classList.length > 0) { classList.remove(classList.item(0)); } 回答3: With ES6 and the

Clear element.classList

北城余情 提交于 2020-01-22 13:06:08
问题 element.classList is of DOMTokenList type. Is there a method to clear this list? 回答1: I'm not aware of a "method" in the sense of a "function" associated with classList . It has .add() and .remove() methods to add or remove individual classes, but you can clear the list in the sense of removing all classes from the element like this: element.className = ""; 回答2: var classList = element.classList; while (classList.length > 0) { classList.remove(classList.item(0)); } 回答3: With ES6 and the

Vue 概况以及核心

妖精的绣舞 提交于 2020-01-22 10:45:10
2013年底作为尤雨溪个人实验项目开始开发 2014年2月 公开发布 截至目前所经历的版本vue0.11、 vue1.0、vue2.0(2016年10月) vue本身并不是框架而是结合周边生态构成一个灵活的、渐进式的框架(主张最少—是轻量级视图,做了自己该做的事,没有做不该做的事情。他对项目的参与性小,在项目中还可以使用其他类库) React 2010年01月出来的,作者:Misko Hevery PHP 94年 JS 95年 作者:布莱登·艾克 核心思想 - 数据驱动 在做传统的JQ数据开发过程中,我们会发现给一个Dom在js里面去绑定Dom的click事件,我们在dom里面可能需要对一块dom进行操作,我们就需要获取这个dom的节点通过test或者是class方法修改这个dom也就是说我们js和dom是耦合的,我们需要去js里面大量操作我们的dom,在vue数据驱动中在单页面或者是多页面的开发过程中都会发现在js里仅仅是去调接口,查数据,查完数据之后把这些数据保存在我们的data里面,更多关注的是如何把数据存储在data里面,至于data里面的变量怎么去和dom交互呢,我们只需要关注数据的变动,不需要考虑这个dom节点,我们只需要关注数据,我们把我们的数据拼装好以后,整个页面就构建出来了 (自己理解) - 组件化 我们做页面的过程中,都会有很多页面,有的东西都是公用的

How to select nested DOM elements inside 'ul' element

淺唱寂寞╮ 提交于 2020-01-22 09:24:10
问题 I am looking for a way to collect all <a> tags and load then in an array using Mootool 1.1 or pure javascript. <ul class="menu"> <li> <ul> <li><a href="#">Group One</a> <ul> <li><a href="#">I want</a></li> <li><a href="#">I want too</a></li> </ul> </li> <li><a href="#">Group Two</a> <ul> <li"><a href="#">I want</a></li> <li><a href="#">I want too</a></li> </ul> </li> </ul> </li> </ul> Edit Solution: Thank you all, your responses have helped me find a more precise solution. Mootools 1.1: @