Project address gitee.com/fe521/vue3-…
Composition API is introduced
What is the Composition API
First understand the OPTIONS API, disadvantages of large components are relatively weak, difficult to read and maintain
export default {
data() {},
computed: {},
methods: {}};Copy the code
The Composition API addresses this problem
Code is organized by logical function 1. Code can be grouped together by function 2. You can pull the code out into a fileCopy the code
Composition APIS can also be called Composition based apis
Why use the Composition API
-
The Composition API organizes code according to logical dependencies, providing readability and maintainability
-
Better reuse of logic code based on function composition logic
-
To reuse some logic in the previous optionsAPI, you could use mixins,
But mixins with attributes of the same name will have naming conflicts, and the code will not be visible, the relationship will not be clear, and the source of the attributes will not be understood
-
Composition API is optional in Vue3
How do I use the Composition API
Composition API Setup Reactive reference methods calculate properties Watch Lifecycle...Copy the code