import{ createApp }from'vue'const app =createApp({})// 注册
app.directive('my-directive',{// Directive has a set of lifecycle hooks:// called before bound element's parent component is mountedbeforeMount(){},// called when bound element's parent component is mountedmounted(){},// called before the containing component's VNode is updatedbeforeUpdate(){},// called after the containing component's VNode and the VNodes of its children // have updatedupdated(){},// called before the bound element's parent component is unmountedbeforeUnmount(){},// called when the bound element's parent component is unmountedunmounted(){}})
import{ createApp }from'vue'import App from'./App.vue'const app =createApp(App)
app.directive('focus',{// When the bound element is mounted into the DOM...mounted(el){// Focus the element
console.log(el);
el.focus()}})
app.mount('#app')