Created
October 31, 2019 09:45
-
-
Save amorfati0310/ab7772cb2137229fcad8584165654358 to your computer and use it in GitHub Desktop.
vue Router 설계 관련 궁금
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="BookMarkList"> | |
<GigListByChunk | |
:gigs="chunkList(bookmarks)" | |
:chunk-count="chunkCount" | |
/> | |
</div> | |
</template> | |
<script> | |
import GigListByChunk from '../../shared/GigListByChunk.vue'; | |
import { getBookMarkList } from '../../../../js/api/babel/bookmark.js'; | |
import _ from 'underscore'; | |
export default { | |
name: 'BookMarkList', | |
components: { | |
GigListByChunk, | |
}, | |
data() { | |
return { | |
bookmarks: [], | |
categoryId: Number(this.$route.params.id) || 0 | |
}; | |
}, | |
props: { | |
chunkCount: { | |
type: Number, | |
default: 4, | |
}, | |
}, | |
computed: { | |
categoryID() { | |
return Number(this.$route.params.id) || 0; | |
}, | |
}, | |
methods: { | |
async fetchBookMarkItem(id) { | |
try { | |
console.log('id', id); | |
const { data: { gigs }} = await getBookMarkList(id); | |
this.bookmarks = gigs; | |
} | |
catch(e) { | |
console.log(e); | |
} | |
}, | |
chunkList(curatedContent = [], chunkCount = this.chunkCount) { | |
return _.chunk(curatedContent, chunkCount); | |
}, | |
}, | |
created() { | |
console.log('this.$route', this.$route.params.id); | |
this.fetchBookMarkItem(this.$route.params.id); | |
}, | |
updated() { | |
console.log('updated') | |
} | |
} | |
</script> | |
<style lang="scss"> | |
.GigLists { | |
.flex-gig { | |
flex-basis: calc(25% - 15px); | |
margin-bottom: 40px; | |
} | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<MainWrapper> | |
<div class="container"> | |
<div class="row margin-top-40"> | |
<!-- todo Component 분리 --> | |
<div class="col-xs-12"> | |
<h2><b>찜한 서비스</b></h2> | |
</div> | |
</div> | |
<!-- todo Component 분리 --> | |
<div class="row margin-top-35"> | |
<div class="col-xs-2"> | |
<SideCategoryList | |
:sideCategoryList="sideCategoryList" | |
:portfolioTotalCount="portfolioBookmarksCount" | |
/> | |
</div> | |
<div class="col-xs-10"> | |
<!--BookMarkList and PortfolioList --> | |
<router-view/> | |
</div> | |
</div> | |
</div> | |
</MainWrapper> | |
</template> | |
<script> | |
import { mapActions, mapState } from 'vuex'; | |
import { getBookMarkCountList } from '../../../api/babel/bookmark.js'; | |
import MainWrapper from '../../shared/MainWrapper.vue'; | |
import SideCategoryList from '../../shared/SideCategoryList.vue'; | |
export default { | |
name: 'MyBookMarks', | |
components: { | |
MainWrapper, | |
SideCategoryList | |
}, | |
props: [], | |
data() { | |
return { | |
bookmarks: [], | |
sideCategoryList: [], | |
}; | |
}, | |
computed: { | |
...mapState('common', [ | |
'portfolioBookmarksCount' | |
]) | |
}, | |
methods: { | |
async fetchBookMarkCategoryList() { | |
try { | |
const { data: { categories }} = await getBookMarkCountList(); | |
this.sideCategoryList = categories; | |
} catch(e) { | |
console.log(e); | |
} | |
}, | |
...mapActions('common/', [ | |
'setNavBarCategoryListAction' | |
]), | |
}, | |
created() { | |
// fix navCategory | |
this.setNavBarCategoryListAction('category'); | |
// getCategoryCount | |
this.fetchBookMarkCategoryList(); | |
} | |
}; | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
path: 'my_bookmarks', | |
name: 'MyBookMarks', | |
component: MyBookMarks, | |
children: [ | |
{ | |
path: '/', | |
redirect: 'category/all' | |
}, | |
{ | |
path: 'category/:id', | |
name: 'BookMarkList', | |
component: BookMarkList, | |
}, | |
{ | |
path: 'portfolio', | |
name: 'PortfolioList', | |
component: PortfolioList, | |
}, | |
], | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="row"> | |
<div class="col-xs-12"> | |
<ul class="margin-none list-unstyled"> | |
<li class="category-list-item root-category inline-block cursor active"> | |
<img class="width-20px position-relative" src="/img/category/ic-arrow-right.png" style="top: -2px;" /> | |
<router-link | |
class="plain" | |
to="/my_bookmarks/category/" | |
@click="updateCategoryId" | |
> | |
전체카테고리({{ getTotalBookMarkCount }}) | |
</router-link> | |
</li> | |
</ul> | |
<ul class="margin-none list-unstyled"> | |
<li v-for="categoryItem in sideCategoryList" | |
:key="categoryItem.id" | |
> | |
<!-- <router-link--> | |
<!-- class="plain font-color-light"--> | |
<!-- :to="getCategoryBookMarkLink(categoryItem)"--> | |
<!-- @click="updateCategoryId(categoryItem.id)"--> | |
<!-- >--> | |
<!-- {{ getCategoryItemLabel(categoryItem) }}--> | |
<!-- </router-link>--> | |
<a | |
class="plain font-color-light" | |
@click="updateCategoryId(categoryItem.id)" | |
> | |
{{ getCategoryItemLabel(categoryItem) }} | |
</a> | |
</li> | |
</ul> | |
</div> | |
<div class="row margin-top-10"> | |
<div class="col-xs-12"> | |
<ul class="margin-none list-unstyled"> | |
<li class="category-list-item root-category inline-block cursor "> | |
<img class="width-20px position-relative" src="/img/category/ic-arrow-right.png" style="top: -2px;"> | |
<router-link to="my_bookmarks/portfolio"> | |
포트폴리오 ({{ portfolioTotalCount }}) | |
</router-link> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
import { mapActions } from 'vuex'; | |
export default { | |
name: 'SideCategoryList', | |
components: { | |
}, | |
props: { | |
sideCategoryList: { | |
type: Array, | |
default: () => [] | |
}, | |
portfolioTotalCount: { | |
type: Number, | |
default: 0, | |
} | |
}, | |
computed: { | |
getTotalBookMarkCount() { | |
if (this.sideCategoryList.length) { | |
return this.sideCategoryList.reduce((acc, crr) => { | |
acc += crr.count; | |
return acc; | |
}, 0); | |
} else { | |
return 0; | |
} | |
}, | |
}, | |
methods: { | |
...mapActions('common/', [ | |
'updateBookMarkCategoryIdAction' | |
]), | |
getCategoryItemLabel(categoryItem) { | |
return `${categoryItem.name} (${categoryItem.count})`; | |
}, | |
getCategoryBookMarkLink(categoryItem) { | |
return `/my_bookmarks/category/${categoryItem.id}`; | |
}, | |
updateCategoryId(id = 0) { | |
console.log('id', id); | |
this.updateBookMarkCategoryIdAction(id); | |
} | |
}, | |
}; | |
</script> | |
<style lang="scss"> | |
.GigLists { | |
.flex-gig { | |
flex-basis: calc(25% - 15px); | |
margin-bottom: 40px; | |
} | |
} | |
</style> |
생각해보니 router-link대신에 -> dispatch or MapAction으로 -> api call 하고 -> bookMarkList -> update 시켜주면 ....
https://github.com/jeonghwan-kim/vue-router-sample/blob/master/src/components/Post.vue
watch {
$route: 를 watch할 수 있다 !!!
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
라우터
mybookMarks page 는 자식 컴포넌트로
왼쪽 메뉴 - SideCategoryList.vue
오른쪽 카드를 뿌려줄(포트폴리오냐 카테고리냐에 따라서)BookMarkList.vue PortfolioList.vue router-view로 이루어져 있습니다.