Let's set up a Vue.js 3 development environment. Vue is a progressive framework for building user interfaces. Vue 3 improved performance and made development more convenient compared with earlier versions. We'll use
Vite is a frontend development tool. Unlike traditional bundler-based setups such as Webpack, it uses native ES modules to serve source code during development, so the dev server starts quickly. It often takes less than a second to start, and you can get to work without a complex Webpack configuration.
. npm normally comes with Node.js. Open a terminal, Command Prompt, or PowerShell, and run the command below.
npm create vite@latest
Vite will prompt you for a few choices.
At project name:, enter a name such as my-vue-app.
At Select a framework:, use the arrow keys to select Vue and press Enter.
At Select a variant:, choose JavaScript or TypeScript. For this guide, choose JavaScript.
Vite creates the project folder and starter files. Open the new folder and install the dependencies.
cd my-vue-appnpm install
The npm install command downloads and installs the packages the project needs. When it finishes, start the development server.
npm run dev
The terminal will show an address such as http://localhost:5173. Open it in your browser to see the Vue starter page, with the Vue logo and a โYou did it!โ message in the template shown here.
One of Vue's distinctive features is the .vue file, called a
single-file component
or
SFC
. Each .vue file acts as a self-contained component, like a LEGO brick. It can hold HTML, JavaScript, and CSS together, making related code easier to manage.
. Declare state, write functions that update data, and import other components here. Vue 3's setup attribute makes component logic more concise. With setup, the code runs when each component instance is created, so you can declare reactive data and define functions there.
We set up a Vue 3 project with Vite and looked at each part of a .vue single-file component. SFCs help keep Vue projects organized and make components easier to work with.
Next time, we'll look more closely at Vue template syntax and learn how to display data and handle user input.