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!
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
tinymce is a fully functional rich text editor plug-in, but introducing tinymce into vue is not as smooth as other Vue rich text plug-ins. tinymce itself is not suitable for Vue, and @tinymce/tinymce-vue needs to be introduced, and It is a foreign rich text plug-in and has not passed the Chinese version. You need to download the translation package from its official website (you may need to bypass the firewall). 1. Install related dependencies npminstalltinymce-Snpminstall@tinymce/tinymce-vue-S2. Download the Chinese package 3. Introduce the skin and Chinese package. Create a new tinymce folder in the project public folder and download the
vue3+vite:src uses require to dynamically import images and error reports and solutions. vue3+vite dynamically imports multiple images. If vue3 is using typescript development, require will introduce image errors. requireisnotdefined cannot be used like vue2 such as imgUrl:require(' .../assets/test.png') is imported because typescript does not support require, so import is used. Here is how to solve it: use awaitimport
To achieve partial refresh of the page, we only need to implement the re-rendering of the local component (dom). In Vue, the easiest way to achieve this effect is to use the v-if directive. In Vue2, in addition to using the v-if instruction to re-render the local dom, we can also create a new blank component. When we need to refresh the local page, jump to this blank component page, and then jump back in the beforeRouteEnter guard in the blank component. original page. As shown in the figure below, how to click the refresh button in Vue3.X to reload the DOM within the red box and display the corresponding loading status. Since the guard in the component in the scriptsetup syntax in Vue3.X only has o
Vue implements the blog front-end and needs to implement markdown parsing. If there is code, it needs to implement code highlighting. There are many markdown parsing libraries for Vue, such as markdown-it, vue-markdown-loader, marked, vue-markdown, etc. These libraries are all very similar. Marked is used here, and highlight.js is used as the code highlighting library. The specific implementation steps are as follows: 1. Install dependent libraries. Open the command window under the vue project and enter the following command npminstallmarked-save//marked to convert markdown into htmlnpmins
vue3+ts+axios+pinia realizes senseless refresh 1. First download aiXos and pinianpmipinia in the project--savenpminstallaxios--save2. Encapsulate axios request-----Download js-cookienpmiJS-cookie-s//Introduce aixosimporttype{AxiosRequestConfig ,AxiosResponse}from"axios";importaxiosfrom'axios';import{ElMess
Preface Whether it is vue or react, when we encounter multiple repeated codes, we will think about how to reuse these codes instead of filling a file with a bunch of redundant codes. In fact, both vue and react can achieve reuse by extracting components, but if you encounter some small code fragments and you don’t want to extract another file, in comparison, react can be used in the same Declare the corresponding widget in the file, or implement it through renderfunction, such as: constDemo:FC=({msg})=>{returndemomsgis{msg}}constApp:FC=()=>{return(
The final effect is to install the VueCropper component yarnaddvue-cropper@next. The above installation value is for Vue3. If it is Vue2 or you want to use other methods to reference, please visit its official npm address: official tutorial. It is also very simple to reference and use it in a component. You only need to introduce the corresponding component and its style file. I do not reference it globally here, but only introduce import{userInfoByRequest}from'../js/api' in my component file. import{VueCropper}from'vue-cropper&
After the vue3 project is packaged and published to the server, the access page displays blank 1. The publicPath in the vue.config.js file is processed as follows: const{defineConfig}=require('@vue/cli-service') module.exports=defineConfig({publicPath :process.env.NODE_ENV==='production'?'./':'/&