Vue3Starting Tutorial
Preparation
Before you start learning Vue3, make sure you have completed the following preparations:
- The latest version has been installed. You canDownload and install .
- Learn basic HTML, CSS, and JavaScript knowledge.
Step 1: Create a new project
First, we will create a new Vue3 project.
- Open the command line interface and go to the directory where you want to create the project.
- Run the following command to install the Vue CLI (Vue Command Line Interface):
-
npm install -g @vue/cli
- 1
- 2
- Create a new Vue3 project:
-
vue create my-vue-project
- 1
- 2
Follow the prompts to select the default configuration or manually configure the project. You can also use presetstemplate,likeTypeScriptorVue Router。
Step 2: Write the first oneComponents
Now that we have created a Vue3 project, we will write the first Vue component next.
- Enter the project directory:
-
cd my-vue-project
- 1
- 2
- Open the editor and in the project directory
src
Create a new file under the folder named。
- exist
In the file, write the following code:
-
<template> <div> <h2>Hello, Vue3!</h2> </div> </template> php Copy code <script> export default { name: 'HelloWorld' } </script>
<style> /* Optional: Add style */ </style>
- 1
- 2
- 3
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
Step 3: Use Components
Now that we have written a Vue component, we will use it in our application next.
- Open
src/
document. - Add the following code to the template:
-
<template> <div > <HelloWorld /> </div> </template>
- 1
- 2
- 3
- 4
- 5
- 6
- Add the following code to the script:
-
import HelloWorld from './'; bash Copy code export default { name: 'App', components: { HelloWorld } }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Step 4: Run the application
Now that we have finished writing and using the components, we will run the application next.
- Return to the command line interface.
- Execute the following command to start the development server:
-
npm run serve
- 1
- 2
- Open the browser and accesshttp://localhost:8080。
Further study
By this point, you have successfully gotten started with Vue3 and have written a simple application. Next, you can continue to learn Vue3's documentation and tutorials to gain an in-depth understanding of more features and usage of Vue3.