Home > Web Front-end > Front-end Q&A > What is the difference between directives and components in vuejs

What is the difference between directives and components in vuejs

青灯夜游
Release: 2023-01-07 11:47:18
Original
2581 people have browsed it

Difference: A component generally refers to an independent entity, and the relationship between components is usually tree-like; while an instruction is a Decorator mode, used to rewrite the default behavior of a component, or enhance it to obtain For additional functions, generally speaking, several instructions can be superimposed on the same component to obtain multiple functions.

What is the difference between directives and components in vuejs

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

The difference between instructions and components in vuejs

A component generally refers to an independent entity, and the relationship between components is usually tree-shaped.

The instruction is a Decorator mode, used to override the default behavior of a component, or enhance it to obtain additional functions. Generally speaking, several instructions can be superimposed on the same component to obtain a variety of Function. Some instructions will rely on the component they are applied to implement certain interfaces. For example, the transition instruction in Vue will rely on a bunch of hooks such as enter and leave of the component.

Of course, there are also some powerful instructions in vue, such as v-if and v-for, which can even create or delete components.

For example, the following design:

Gallery is a photo album component.

Transition is an animation command.

ClickLogger is an instruction to open a click log.

Overlay Animation and ClickLogger on Gallery to have animated transition effects when switching, and automatically record logs when clicked.

Related recommendations: "vue.js Tutorial"

The above is the detailed content of What is the difference between directives and components in vuejs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template