vue-pinia-practical/
├── src/
│   ├── stores/
│   │   └── counter.js
│   ├── components/
│   │   ├── CounterDisplay.vue
│   │   └── CounterControls.vue
│   ├── App.vue
│   └── main.js
├── index.html
└── package.json


src/main.js:
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'

const app = createApp(App)

app.use(createPinia())

app.mount('#app')


Create a folder named stores inside src.
Inside it, create counter.js.
File: src/stores/counter.js :
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({
    count: 0
  }),

  actions: {
    increment() {
      this.count++
    },

    decrement() {
      this.count--
    },

    reset() {
      this.count = 0
    }
  }
})

Create a folder named components inside src.
Create CounterDisplay.vue.
File: src/components/CounterDisplay.vue :
<script setup>
import { useCounterStore } from '../stores/counter'

const counter = useCounterStore()
</script>

<template>
  <div class="display">
    <h2>Current Counter</h2>

    <p class="number">{{ counter.count }}</p>
  </div>
</template>

<style scoped>
.display {
  margin: 20px 0;
  padding: 20px;
  background: #e0f2fe;
  border-radius: 10px;
}

.number {
  font-size: 40px;
  font-weight: bold;
  color: #2563eb;
}
</style>

Create CounterControls.vue.
File: src/components/CounterControls.vue :
<script setup>
import { useCounterStore } from '../stores/counter'

const counter = useCounterStore()
</script>

<template>
  <div class="controls">
    <button @click="counter.increment()">
      Increase
    </button>

    <button @click="counter.decrement()">
      Decrease
    </button>

    <button @click="counter.reset()">
      Reset
    </button>
  </div>
</template>

<style scoped>
.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  background: #2563eb;
  color: white;
  cursor: pointer;
}

button:hover {
  background: #1d4ed8;
}
</style>

src/App.vue:
<script setup>
import CounterDisplay from './components/CounterDisplay.vue'
import CounterControls from './components/CounterControls.vue'
</script>

<template>
  <main>
    <h1>Vue + Pinia State Management</h1>

    <p>A simple application demonstrating shared state.</p>

    <CounterDisplay />

    <CounterControls />
  </main>
</template>

<style>
body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f1f5f9;
}

main {
  max-width: 600px;
  margin: 60px auto;
  padding: 25px;
  text-align: center;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 15px #00000015;
}

h1 {
  color: #1e293b;
}
</style>
