Summary of Vue front-end interview questions (33) How to use Vue custom instructions? Detailed

What custom instruction?

The registration method of instructions and filters, components are the same,
they are divided into global registration and local registration
1. Global registration

Vue.directive('name',{
    
    })

2. Partial registration

directive:{
    
    
 name:''
}

Then use it directly in the module

Vue also provides hook functions for several custom instructions

bind: Called when the instruction is bound to the element for the first time, and only executed once.

inserted: The bound element is called when it is inserted into the DOM of the parent node.

update: called when the component is updated.

componentUpdated: called when components and subcomponents are updated.

unbind: Called when the instruction is unbound from the element, only executed once.

Guess you like

Origin blog.csdn.net/Rick_and_mode/article/details/108655120