Introduction & Project setup
How to create advanced vue3 component with pinia?
How to setup project
Vue3 + VITE
https://vuejs.org/guide/quick-start.html#quick-start ๋ฅผ ์ฐธ๊ณ ํด Vue3 ํ๋ก์ ํธ๋ฅผ ์์ฑํฉ๋๋ค.
Let's say you already have Vite + Vue3 project.
์๋ก์ด Vue3 ํ๋ก์ ํธ๋ฅผ ์์ฑํ์ธ์. Vite๋ฅผ ์ฌ์ฉํ์ง ์์ ์ด์ ๊ฐ ์์ผ๋ ๊ผญ Vite๋ฅผ ์ฌ์ฉํด ํ๋ก์ ํธ๋ฅผ ์์ฑํฉ๋๋ค. ์ด๋ฏธ ์์ฑํ Vue3 ํ๋ก์ ํธ๊ฐ ์๋ค๋ฉด ์คํตํฉ๋๋ค.
[optional] node ๋ฒ์ ์ 18.16.1
nvm use 18.16.1
Storybook ์ค์น
pnpm dlx storybook@latest init
[์ฐธ๊ณ ] package.json์ storybook dependencies
"@storybook/addon-essentials": "^7.5.3",
"@storybook/addon-interactions": "^7.5.3",
"@storybook/addon-links": "^7.5.3",
"@storybook/blocks": "^7.5.3",
"@storybook/testing-library": "^0.2.2",
"@storybook/vue3": "^7.5.3",
"@storybook/vue3-vite": "^7.5.3",
"storybook": "^7.5.3"
๊ฐ๋ฐ ์๋ฒ ์คํ
pnpm storybook
Storybook ์ค์

๊ธฐ๋ณธ ํฌํธ๊ฐ 6006, localhost:6006์ผ๋ก ์ ์์ ์๋์ ๊ฐ์ด ์คํ ๋ฆฌ๋ค์ด ์๊น๋๋ค.

์์ฑํ ์ปดํฌ๋ํธ๋ฅผ ์คํ ๋ฆฌ๋ถ์์ ํ ์คํธํ๊ธฐ ์ํด์๋ ๋ ๊ฐ์ง ํ์ผ์ ํจ๊ป ์์ฑํด์ผ ํฉ๋๋ค.
SFC (๋ทฐ ์ปดํฌ๋ํธ)
<template>
<div class="flex items-center p-2 bg-white rounded-lg shadow-sm hover:bg-gray-100">
<img
v-if="userData && userData.avatar"
:src="userData.avatar"
alt="User Avatar"
class="w-8 h-8 rounded-full"
/>
<span v-if="userData" class="ml-3 text-sm font-medium text-gray-700">
{{ userData.name }}
</span>
<span v-if="userData.loading" class="ml-3 text-sm font-medium text-gray-700">
Loading...
</span>
</div>
</template>
<script setup>
import { storeToRefs } from 'pinia';
import { useUserStore } from '../../stores/user'
const userStore = useUserStore();
const { userData } = storeToRefs(userStore);
</script>
story
import UserProfile from './UserProfile.vue';
import { useUserStore } from '@/stores/user';
export const Base = {
render: (args) => ({
components: { UserProfile },
setup() {
const userStore = useUserStore();
userStore.userData = {
name: "John Doe",
email: "[email protected]",
id: 53,
avatar: "https://api.dicebear.com/7.x/fun-emoji/svg"
}
return { args }
},
template: /* html */`
<UserProfile
v-bind="args"
/>
`,
}),
args: {
alt: "storybook Profile"
}
}
export default {
component: UserProfile
}
๊ฐ์ด ์ค์นํ๋ฉด ์ข์ vscode extension


์ฃผ์ ์ฌ์ฉ์ ๋งํฌ์ ํ์ด๋ผ์ดํ ์ด ๋๊ฒ ํด์ค๋๋ค.
Last updated