1.自定义指令 directive
作用:操作dom,或操作第三方基于dom的插件
html代码
<div id="app">
<input type="text" v-focus="flag">
<button @click="flag=!flag">更换</button>
</div>
js代码
var vm=new Vue({
el:"#app",
data(){
return{
flag:false
}
},
directives:{
//自定义v-focus指令
"focus":{
//当被插入的时候用inserted
//只绑定一次 bind
//更新时候运行update
update(el,binding){
//el对应的节点
//binding.value指令的值
console.log(el,binding);
if(binding.value){
el.focus();
}
}
}
}
})
2. 管道或过滤 filter
作用:格式化数据。
html代码