其他分享
首页 > 其他分享> > Vue常用特性

Vue常用特性

作者:互联网

强制转换成数值型(原本文本框是字符串)   v-model.number

去掉空格     v-model.trim 转变为change事件  失去焦点才改变值    v-model.lazy   自定义指令   directive   <div id="app">         <input type="text" v-focus>   //使用自定义指令必须加v-  ,这个绑定的input就执行里面的函数         <input type="text">     </div>  Vue.directive('focus', {             inserted: function (el) {                 el.focus();             }         }); 带参数的自定义指令  Vue.directive("color", {         bind: function (el, binding) {           console.log(binding.value.color); //blue           console.log(binding.value); //返回 Object   里面包含color           console.log(binding.value.name); //undefind           el.style.backgroundColor = binding.value.color;         }});     Vue.directive('red',{       bind:function(el,binding){         console.log(binding.value.red)         el.style.backgroundColor=binding.value.red;       }     }); bind 和 inserted 共同点: dom插入都会调用,bind在inserted之前 不同点: bind 时父节点为 null inserted 时父节点存在。 bind是在dom树绘制前调用,inserted在dom树绘制后调用 bind: function (el) { console.log(el.parentNode) // null console.log('bind') }, inserted: function (el) { console.log(el.parentNode) // <div class="directive-box">...</div> console.log('inserted') }

标签:el,常用,Vue,console,log,bind,binding,特性,inserted
来源: https://www.cnblogs.com/renshen/p/13267948.html