vuejs
Overview
Vue.js is a progressive JavaScript framework for building user interfaces. It is designed to be incrementally adoptable and focuses on the view layer, making it easy to integrate with other libraries or existing projects.
Quick Start
Create Repository from Template
On your dashboard, go to the Tools & Deployment tab. Click the "New Repository" button, select the Vue.js template from the dropdown, enter a repository name and subdomain, then click "Create Repository".
Clone Your Repository
git clone https://<git-server>/<username>/<repo-name>.git
cd <repo-name>
Install Dependencies
npm install
Start Development Server
npm run dev
Open http://localhost:4200 in your browser.
Build & Push
npm run build
git add .
git commit -m "Initial setup"
git push origin main
Local Development with Docker
If you don't have Node.js installed locally, you can use Docker to run Vue commands. The project includes a Dockerfile for production builds with nginx.
Prerequisites
Install Docker Desktop for your operating system (Windows, Mac, or Linux).
Running Commands with Docker
# Run npm install
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm install
# Run development server (accessible at localhost:4200)
docker run --rm -v $(pwd):/app -w /app -p 4200:4200 node:lts-alpine npm run dev
# Build for production
docker run --rm -v $(pwd):/app -w /app node:lts-alpine npm run build
Project Structure
Understanding where files are located:
├── src/
│ ├── assets/ # Static assets (images, fonts)
│ ├── components/ # Vue components
│ ├── views/ # Page components
│ ├── router/ # Vue Router configuration
│ ├── stores/ # Pinia stores
│ ├── App.vue # Root component
│ └── main.js # Application entry point
├── public/ # Public static files
├── index.html # HTML entry point
├── vite.config.js # Vite configuration
├── package.json # Dependencies and scripts
└── Dockerfile # Docker build configuration
Common Tasks
Creating a Component
Create .vue files in src/components/:
<!-- src/components/Button.vue -->
<script setup>
defineProps({
label: String
});
const emit = defineEmits(['click']);
</script>
<template>
<button
class="bg-blue-500 text-white px-4 py-2 rounded"
@click="emit('click')"
>
{{ label }}
</button>
</template>
Adding a Route
Edit src/router/index.js:
import { createRouter, createWebHistory } from 'vue-router';
import Home from '../views/Home.vue';
import About from '../views/About.vue';
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About }
]
});
export default router;
Using Pinia Store
Create a store in src/stores/:
// src/stores/counter.js
import { defineStore } from 'pinia';
export const useCounterStore = defineStore('counter', {
state: () => ({ count: 0 }),
actions: {
increment() { this.count++ },
decrement() { this.count-- }
}
});
Using Tailwind CSS
Tailwind CSS 4 is pre-configured. Use classes directly in your templates:
<div class="bg-blue-500 text-white p-4 rounded-lg">
Hello Tailwind!
</div>
Useful Commands
npm run dev
Start development server (port 4200)
npm run build
Build for production
npm run preview
Preview production build locally
npm run test:unit
Run unit tests with Vitest
npm run lint
Check and fix code style
npm run format
Format code with Prettier
Troubleshooting
npm install fails with permission errors
Cause: Permission issues with npm cache or node_modules.
Solution: Delete node_modules folder and package-lock.json, then run npm install again.
Port 4200 already in use
Cause: Another process is using port 4200.
Solution: Use a different port: npm run dev -- --port 3000 or stop the other process.
Component not updating
Cause: Reactivity not properly set up.
Solution: Use ref() for primitives and reactive() for objects. Access ref values with .value in script, but not in template.
Router not working
Cause: RouterView not in App.vue or router not registered.
Solution: Ensure <RouterView /> is in App.vue and router is added with app.use(router) in main.js.
Build fails after deployment
Cause: Build errors or missing dependencies.
Solution: Run npm run build locally first to check for errors before pushing.
Deployment Workflow
Every time you push code to Git, your application is automatically built and deployed:
Your deployed application URL follows this format:
https://<your-subdomain>-<repo-name>.<session-domain>
Example: https://student01-module-a.demo.nstrim.app