미해결
Vue.js 완벽 가이드 - 실습과 리팩토링으로 배우는 실전 개념
mixin 질문있습니다.
라우트에서 다음과 같이 전부 리스트 컴포넌트를 불러오고 mixin을 하면 왜 처음에 들어간 글 리스트에서 다른 페이지로 갔을 때, 데이터가 업데이트 되지 않는 걸까요??mixin 내부에서는 route.name에 따라서 넘기는 변수가 달라져서 원래는 각각 페이지에 맞는 데이터가 fetch되어야 하는게 아닌가요?? mixinimport bus from "@/utils/bus";
// mixin
export default {
// 재사용할 컴포넌트 옵션 & 로직
created() {
bus.$emit("start:spinner");
this.$store
.dispatch("FETCH_LIST", this.$route.name)
.then(() => {
console.log("fetched", this.$route.name);
bus.$emit("end:spinner");
})
.catch((err) => {
console.error(err);
});
},
};routes/index.jsexport const router = new VueRouter({
mode: "history", // 표시되는 url => root/#/ 형식을 없애줌
routes: [
{
path: "/",
redirect: "/news",
},
{
path: "/news", // 주소
name: "news",
// component: createListView("NewsView"), // HOC
component: ListView,
},
{
path: "/ask",
name: "ask",
component: ListView,
},
{
path: "/jobs",
name: "jobs",
component: ListView,
},
{
path: "/user/:id",
component: UserView,
},
{
path: "/item/:id",
component: ItemsView,
},
],
});