📖 Scenario: You want to start a new website project using Vue 3.4+. Vue helps you build interactive web pages easily.
🎯 Goal: Create a new Vue project with a basic setup using the Composition API and <script setup> syntax.
📋 What You'll Learn
Create a new Vue project folder
Add a main.js file to start the app
Create an App.vue component with <script setup>
Render a simple message inside the app
💡 Why This Matters
🌍 Real World
Starting a new Vue project is the first step to building interactive web apps for websites, dashboards, or mobile apps.
💼 Career
Vue is a popular frontend framework used by many companies. Knowing how to set up a project is essential for frontend developer roles.
Progress0 / 4 steps
1
Create the project folder and main.js
Create a folder named my-vue-app. Inside it, create a file called main.js with this exact content: import { createApp } from 'vue'; import App from './App.vue'; createApp(App).mount('#app');
Vue
Hint
Use import statements to bring in Vue and your main component. Then create and mount the app to #app.
2
Create the App.vue component with script setup
Create a file named App.vue in the my-vue-app folder. Add a <template> with a <h1> that says Hello Vue!. Add a <script setup> block below the template.
Vue
Hint
The <script setup> tag is a new way to write Vue components simply. The <template> holds your HTML.
3
Add the HTML file to mount the Vue app
Create an index.html file inside my-vue-app. Add a <div> with id="app" inside the <body>. Also add script tag to load main.js at the end of the body.
Vue
Hint
The div with id="app" is where Vue will show your app. The script tag loads your JavaScript.
4
Run the Vue app with a simple message
Ensure your App.vue template shows Hello Vue! inside an <h1>. This completes your basic Vue project setup.
Vue
Hint
Check that your <h1> text exactly matches Hello Vue!.
Practice
(1/5)
1. What is the correct command to start creating a new Vue project using the latest recommended method?
easy
A. npm create vue@latest
B. vue create project
C. npm install vue
D. npm run vue
Solution
Step 1: Understand the official Vue project creation command
The recommended way to create a new Vue project is using npm create vue@latest, which scaffolds the project with the latest setup.
Step 2: Compare with other commands
Other commands either install Vue or run scripts but do not create a new project scaffold.
Final Answer:
npm create vue@latest -> Option A
Quick Check:
Use npm create vue@latest to start a Vue project [OK]
Hint: Use 'npm create vue@latest' to start a new Vue project [OK]
Common Mistakes:
Using 'vue create' which is from older Vue CLI
Trying to install Vue instead of creating project
Running npm scripts unrelated to project creation
2. Which of the following commands correctly runs the development server after creating a Vue project?
easy
A. vue serve
B. npm start
C. npm run dev
D. npm run start
Solution
Step 1: Identify the standard Vue dev server command
After creating a Vue project, the usual command to start the development server is npm run dev.
Step 2: Understand why other options are incorrect
npm start or npm run start are common in other projects but not default in Vue. vue serve is not standard in Vue 3 projects created with the latest tool.
Final Answer:
npm run dev -> Option C
Quick Check:
Run dev server with npm run dev [OK]
Hint: Use 'npm run dev' to start Vue dev server [OK]
Common Mistakes:
Using 'npm start' which is not default in Vue projects
Trying 'vue serve' which is outdated
Confusing 'npm run start' with 'npm run dev'
3. After running npm create vue@latest and answering setup questions, what will happen when you run npm run dev inside the project folder?
medium
A. The Vue app compiles and opens a local server showing the default welcome page.
B. It installs Vue dependencies but does not start any server.
C. It throws an error because the project is not built yet.
D. It deletes the project files and exits.
Solution
Step 1: Understand the purpose of 'npm run dev'
This command starts the development server, compiles the Vue app, and serves it locally.
Step 2: Recognize expected behavior after project setup
After setup, running this command shows the default Vue welcome page in the browser.
Final Answer:
The Vue app compiles and opens a local server showing the default welcome page. -> Option A
Quick Check:
Dev server runs and shows app page [OK]
Hint: Run 'npm run dev' to see your Vue app live locally [OK]
Common Mistakes:
Expecting 'npm run dev' to only install dependencies
Thinking the command builds but does not serve
Confusing errors with missing setup steps
4. You ran npm create vue@latest but got an error saying 'command not found'. What is the most likely cause?
medium
A. You forgot to create a project folder before running the command.
B. You do not have Node.js and npm installed or they are not in your system PATH.
C. You need to run the command inside an existing Vue project folder.
D. The command requires an internet connection but you are offline.
Solution
Step 1: Understand the error 'command not found'
This error usually means the system does not recognize the command because Node.js and npm are missing or not set up properly.
Step 2: Evaluate other options
Creating a folder or internet connection issues do not cause 'command not found'. Running inside a Vue project folder is not required to create a new project.
Final Answer:
You do not have Node.js and npm installed or they are not in your system PATH. -> Option B
Quick Check:
Missing Node.js/npm causes 'command not found' [OK]
Hint: Check Node.js and npm installation if command not found error appears [OK]
Common Mistakes:
Assuming folder creation is required before command
Thinking command must run inside Vue project
Ignoring system PATH setup for Node.js/npm
5. You want to create a Vue project with TypeScript support and router enabled. Which step should you do during npm create vue@latest setup to achieve this?
hard
A. Edit the package.json file after creation to add TypeScript and Router dependencies.
B. Manually install TypeScript and Vue Router after project creation.
C. Run npm create vue@latest --typescript --router to auto-enable features.
D. Select TypeScript and Router options when prompted during the setup questions.
Solution
Step 1: Understand the interactive setup process
When running npm create vue@latest, it asks questions to customize your project, including enabling TypeScript and Router.
Step 2: Recognize the correct way to enable features
Selecting these options during setup automatically configures the project with needed dependencies and settings.
Step 3: Evaluate other options
Manual installs or editing files after creation are possible but not the recommended or easiest way. Command line flags such as npm create vue@latest --typescript --router are not supported.
Final Answer:
Select TypeScript and Router options when prompted during the setup questions. -> Option D
Quick Check:
Choose features during setup for easy config [OK]
Hint: Pick features during setup prompts to configure project easily [OK]
Common Mistakes:
Trying to add features only after project creation
Assuming command line flags auto-enable features
Editing package.json manually instead of using setup
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.