Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- react
- javascript #localstorage #stringify #parse
- PersistentVolume
- localstorage
- MPA
- basepath
- CKEditor4
- v-combobox
- browserstorage
- vuejs #pinia #vuetify3
- vworld
- nextjs
- sesstionstorage
- Yarn
- vue3
- 인터넷 #클라이언트 #서버 #포트 #ipadress #domainname
- javascript #컴파일 #인터프리터
- postman
- 라우터 #NAT #포트 #포트포워딩 #유동고정아이피 #DHCP
- 맥 #나스 #SMA
- JavaScript
- vuejs
- kubernetes
- github action #tistory
- vue #vue-router
- mixedcontent
- vuetify3
- OpenLayers
- MongoDB
- PersistentVolumeClaim
Archives
- Today
- Total
月亮
vue-router를 이용해서 defaultLayout, 페이지 레이아웃 구성하기 본문
전제조건 : vue3, vue-router 프로젝트 생성
1. 컴포넌트 생성
// src/views/Home.vue
<template>
<v-container class="text-center">
<h1>Home</h1>
<v-btn class="pa-3" to="/about">Go To About</v-btn>
<br />
<v-btn color="primary" class="ma-3" to="/profile">Go To Profile</v-btn>
</v-container>
</template>
<script lang="ts" setup></script>
// src/views/About.vue
<template>
<v-container class="text-center">
<h1>About</h1>
<v-btn class="pa-3" to="/">Go To Home</v-btn>
<br />
<v-btn color="primary" class="ma-3" to="/profile">Go To Profile</v-btn>
</v-container>
</template>
<script lang="ts" setup></script>
// path: src/views/Profile.vue
<template>
<v-container class="text-center">
<h1>Hello, this my profile page</h1>
<v-btn to="/">Go To Home</v-btn>
</v-container>
</template>
<script lang="ts" setup>
</script>
2. router.js 생성
// path: src/router/routes.ts
import { RouteRecordRaw } from 'vue-router';
const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Home',
component: () => import(/* webpackChunkName: "home" */ '../views/Home.vue'),
},
{
path: '/about',
name: 'About',
component: () =>
import(/* webpackChunkName: "about" */ '../views/About.vue'),
},
{
path: '/profile',
name: 'Profile',
component: () =>
import(/* webpackChunkName: "profile" */ '../views/Profile.vue'),
},
];
export default routes;
// path: src/router/index.ts
import { createRouter, createWebHistory } from 'vue-router';
import routes from './routes';
const router = createRouter({
history: createWebHistory(),
routes,
});
export default router;
3. main.js에 추가
// path: src/main.js
import { createApp } from 'vue';
import './style.css';
import App from './App.vue';
// line 1: import the router
import router from './router';
const app = createApp(App);
// line 2: use the router
app.use(router);
app.mount('#app');
4. app.vue 추가
// path: src/App.vue
<script>
</script>
<template>
<!-- Add this line -->
<router-view />
</template>
5. 레이아웃 정의 defaultLayout생성
// Path: src\layouts\TheDefaultLayout.vue
<script>
</script>
<template>
<v-layout>
<v-main>
<!--The <slot> element is a slot outlet that indicates
where the "VIEW" content should be rendered.-->
<slot></slot>
</v-main>
</v-layout>
</template>
// Path: src\layouts\TheDashboardLayout.vue
<script>
</script>
<template>
<v-layout>
<v-app-bar color="grey-lighten-2"></v-app-bar>
<v-navigation-drawer color="grey-darken-2" permanent></v-navigation-drawer>
<v-main>
<!--The <slot> element is a slot outlet that indicates
where the "VIEW" content should be rendered.-->
<slot></slot>
</v-main>
</v-layout>
</template>
`slot`은 한 구성 요소에서 다른 구성 요소로 전달되는 콘텐츠를 표시하기 위해 vuejs에서 제공하는 예약된 공간입니다. vuejs에는 명명된 슬롯과 명명되지 않은(기본) 슬롯의 두 가지 유형의 슬롯이 있습니다.
6. 경로 레이아웃 연결, router.js 업데이트
// path: src/router/routes.js
const routes = [
{
path: '/',
name: 'Home',
component: () => import(/* webpackChunkName: "home" */ '../views/Home.vue'),
meta: {
layout: 'Default',
},
},
{
path: '/about',
name: 'About',
component: () =>
import(/* webpackChunkName: "about" */ '../views/About.vue'),
meta: {
layout: 'Default',
},
},
{
path: '/profile',
name: 'Profile',
component: () =>
import(/* webpackChunkName: "profile" */ '../views/Profile.vue'),
meta: {
layout: 'Dashboard',
},
},
];
export default routes;
출처에 추가 과정 있음!! 여기까지만 해도 생성 가능
출처
https://honeydanji.healthsarang.com/2023/03/code-vue3-layouts.html
https://blog.izem.dev/a-vue-3-users-guide-to-creating-complex-layouts
https://vueschool.io/articles/vuejs-tutorials/composing-layouts-with-vue-router/
반응형
'vue.js' 카테고리의 다른 글
[vuetify3] v-combobox 사용자 입력 비활성화 (0) | 2023.07.26 |
---|---|
[vue.js] 헷갈리는 부분 정리 (작성중...) (0) | 2023.06.20 |
[vue.js] vue3 + vuetify3 세팅 (vue-cil+webpack+vuetify3) , 디렉토리 구성 🌿 (0) | 2023.06.20 |
[vue.js] vue3에서 filter 사용하기🤔 (0) | 2023.05.08 |
[vue.js+vuetify3+pinia] 전역 모달 (Alert dialog, Confirmation Modal) 만들기 🤔 (0) | 2023.04.12 |
Comments