Views: 1898
Last Modified: 15.04.2022

Local directive - const directive = {...}

Directive parameter object: you learn more in Vue documentation.

const directive = {
	...definition...
};

Example

export const focus = {
	mounted: (el) => el.focus()
};

Please note, the first letter of variable is in lower case. This is done to avoid re-naming it locally after registering the directive in your application or component.

import {focus} from './directives/focus';

const Component = {
	directives: {
		focus
    },
    template: `
        <input v-focus>   
    `
}

Important! If you use animation for display (showing content due to visibility area limits), then do not use autofocus directives, because the browser will momentarily set the focus on the element outside the visibility limits and animation won't look as expected.





Courses developed by Bitrix24