Member-only story

Vue3- Use and Encapsulation Concept of Custom Hooks Functions

Shawn Kang
7 min readJan 29, 2024

--

Vue series of articles

What are hooks?

In Vue3, hooks are a kind of function writing style, which essentially encapsulates certain independent functional Javascript code from a file.

The main purpose of it is that Vue3 draws from a mechanism in React, which is used to share state logic and side effects in function-based components, thereby improving code reusability.

Note: Hooks are somewhat similar to mixins in Vue2, but compared to mixins, hooks make it clearer where the reused code originates from, making it easier to understand.

Advantages of hooks

  • Hooks encapsulate components as independent logic. Its internal attributes, functions, etc. have a reactive effect that’s associated to external components.
  • The function of custom hooks is similar to the mixin technology used in Vue2, which is convenient and easy to use.
  • It is highly cohesive and loosely coupled, and it is reusable when encapsulated with Vue3’s combination…

--

--

Shawn Kang
Shawn Kang

Written by Shawn Kang

Focusing on front-end development and internet writing. Sharing technical tutorials and original fiction. https://skstory.online/

Responses (1)

Write a response