How to get started with vue3 quickly, learn these APIs!
青灯夜游
Release: 2022-03-18 19:40:07
forward
2696 people have browsed it
How to get started with vue3 quickly? This article will share with you a few APIs. Once you learn these APIs, you can get started directly with vue3. I will slowly learn about the others. I hope it will be helpful to everyone!
Those who have developed projects with vue2 want to get started with vue3 quickly. It is enough to be familiar with a few APIs. Other features will be slowly understood in the process of using vue3.
Anyone who studies some API principles after becoming familiar with its use will slowly be able to master vue3.
Moreover, when using vue3 combined with ts, the proportion of ts in the development process is not that big. If you know the basics of ts shared before, it is enough for development. [Related recommendations: vuejs video tutorial]
Global API and application API
A new concept of vue3, return An application instance that provides an application context. The entire component tree mounted by the application instance shares the same context:
new Vue({
router,
store,
render: (h) => h(App),
}).$mount("#app");
Copy after login
Then those APIs that used to use Vue. now use this one. Application example app.:
vue2
vue3
##Vue.component
app.component
##app.config
app.config
app.directive
app.directive
app.mixin
app.mixin
app.use
app.use
Other APIs like nextTick, h, etc. are used directly from the vue structure:
import { createApp, h, nextTick } from 'vue'
Copy after login
composition API
tips
This is no longer used in vue3
vue3 components do not require a root tag, but there will be WarningExtraneous non-props attributes
It is recommended to use single-file components, and the subsequent implementation codes are single-file components
setup
This is so important, vue3 uses this function as the entry point. Receives two parameters props and context.
The function will be executed before beforeCreate and created. It can be said that it replaces beforeCreate and created and becomes the new life cycle.
The new composition API is written in the setup function.
Props are the props of vue2, and context provides attrs, slots, emit, etc.
By returning an object, the responsive data is exposed to the template, which is equivalent to vue2 data. The difference is that the function is also exposed to the template in this way:
vue3 also provides a single file component (recommended). Add setup to the script, and the code inside will be compiled into a setup function.
A few important points:
The top-level binding will be exposed to the top-level binding declared by the template
(including variables, function declarations, and import introductions content) can be used directly in the template
Reactive data, components, etc. can also be used directly:
The above is the detailed content of How to get started with vue3 quickly, learn these APIs!. For more information, please follow other related articles on the PHP Chinese 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