Skip to content

Instantly share code, notes, and snippets.

@amorfati0310
Created October 31, 2019 09:45
Show Gist options
  • Save amorfati0310/ab7772cb2137229fcad8584165654358 to your computer and use it in GitHub Desktop.
Save amorfati0310/ab7772cb2137229fcad8584165654358 to your computer and use it in GitHub Desktop.
vue Router 설계 관련 궁금
<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>
<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>
{
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,
},
],
},
<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>
@amorfati0310
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment