Except for the core directive of the default setting v-model and v-show Vue also allows you to register custom directives

Let’s register a global directive. The v-focus function of this directive is to get focus on the element when the page is loaded

2.16.1. Example

When loading the page,input Element automatically obtains focus:

We can also use it in an example directives option to register local directives, so that instructions can only be used in this instance:


2.16.2. Example

When loading the page,input Element automatically obtains focus: