directive
- 需求:自定义一个指令,要求打开页面,input框自动聚焦
Vue.directive("focus",{
bind(el,bindiing){
el.focus();
console.log("bing");
},
inserted(el){
console.log("inserted");
el.focus();
}
});
Vue.component("ComponentA", {
methods: {
handleClick() {
this.count++;
},
},
data() {
return {
count: 0,
};
},
template: `<div>ComponentA
{{count}}
<input type="text" v-focus="123"></input>
</div>`,
});
app = new Vue({
el: `#app`,
template: `
<div>{{msg}}
<ComponentA></ComponentA>
</div>`,
data: {
msg: "hello world",
},
});