Quasar SSR) meta 설정하기
Vue.js 와 Quasar 프레임워크를 사용하면서 한동안 해결하지 못했던 문제를 정리해본다.
Quasar 프레임워크에는 SSR(Server Side Rendering) 을 제공해준다.
Prefetch 기능인데, 해당 기능으로 SSR 작업을 하면된다.
여기서 문제가 있었는데, 바로 meta data 설정이다.
export default { meta: { title: 'Index Page', titleTemplate: title => `${title} - My Website`, } }
물론 위처럼하면 정적 데이터를 가지고 title을 설정해주는것이니 아무런 문제가 없다.
하지만
export default { meta: { title: this.getData.title, titleTemplate: title => `${title} - My Website`, }, preFetch({ store, currentRoute, previousRoute, redirect, ssrContext }) { let params = currentRoute.params.id; return store.dispatch("project/fetchData", data); } computed: { ...mapGetters("project", ["getData"]), } }
위 처럼, preFetch 의 데이터를 바로 가져오려고 하면 getData가 없다며 오류를 발생시킨다.
그럼 어떻게 해결해야할까?
나는 이와 같은 방법으로 meta 설정을 하였다.
export default { meta(){ return { title: this.getDataFunction.title, titleTemplate: title => `${title} - My WebSite` } }, preFetch({ store, currentRoute, previousRoute, redirect, ssrContext }) { let params = currentRoute.params.id; return store.dispatch("project/fetchData", data); } computed: { ...mapGetters("project", ["getData"]), getDataFunction(){ return this.$store.state.project.data || {} } } }
이미 sotre.dispatch() 를 통해 state에 저장해준 값을 가져오는것이기때문에, 위처럼 작업해주면 SSR에서도 meta data를 쉽게 설정해줄 수 있다.
'Programming > Vue.js' 카테고리의 다른 글
Vue.js(Quasar) 데이터 매칭문제 해결 (0) | 2020.01.29 |
---|---|
Vue.js 플러그인 사이트 (0) | 2020.01.13 |
Quasar 프레임워크 SSR (0) | 2020.01.13 |
(Vue.js 오류 해결) 같은 경로일때 로드가 되지 않는 문제. (0) | 2018.03.16 |
Vue 관련 스크립트 모음 (0) | 2018.02.28 |
댓글
이 글 공유하기
다른 글
-
Vue.js(Quasar) 데이터 매칭문제 해결
Vue.js(Quasar) 데이터 매칭문제 해결
2020.01.292020/01/20 - [문제/Vue.js] - SSR 데이터 매칭 문제……… SSR 데이터 매칭 문제……… Quasar SSR에서 문제… /member/:id /member/:id 라는 라우터가있을때 :id 를 axios.post(`/member/${memberid}`) 이와같은식으로 요청하지만, 해당부분은 SSR 처리를하는데, axios.interceptors.response 에서는… focuspro.tistory.com 위 문제뿐만아니라, 거의 모든 문제를 해결한것같아서 상당히 만족스럽다. 사실 위 문제는 문제도 아니였…. 두가지 해결방안이있다. src/router/index.js 에서 해결하거나 [비추!] // 이유는 뭐… 안써도 다들아시겠지만… // 아래와같은 코드는 결국 2… -
Vue.js 플러그인 사이트
Vue.js 플러그인 사이트
2020.01.13Vue.js 플러그인 관련 사이트들이다. 아래사이트에서 수많은 Vue.js 예제들을 확인가능하니, 개발에 어려움시 참고하면 도움이 될것같다. https://vuejsexamples.com Vue.js Examples A nice collection of often useful examples done in Vue.js vuejsexamples.com https://madewithvuejs.com A collection of projects made with Vue.js – Websites, UI Components, Frameworks, Apps and more! A collection of projects made with Vue.js – Websites, UI Components, Frameworks… -
Quasar 프레임워크 SSR
Quasar 프레임워크 SSR
2020.01.13https://quasar.dev Quasar Framework - Build high-performance VueJS user interfaces in record time Developer-oriented, front-end framework with VueJS components for best-in-class high-performance, responsive websites, PWA, SSR, Mobile and Desktop apps, all from the same codebase. Sensible people choose Vue. Productive people choose Quasar. Be both. quasar.dev 최근 quasar(퀘이사) 프레임워크로 SSR 작업을 하게되었는데,… -
(Vue.js 오류 해결) 같은 경로일때 로드가 되지 않는 문제.
(Vue.js 오류 해결) 같은 경로일때 로드가 되지 않는 문제.
2018.03.16Vue.js 로 프론트를 개발중에 다음과 같은 에러가 발생하였다. /view/[view_id] 와 같은 경로가 있는데, 해당 경로는 view_id를 가진 게시물을 볼 수 있는 경로이다. /view/[view1] /view/[view2] 위와 같은 2개의 링크가 있는데, view1으로는 잘이동이되나, view1에서 view2로 이동하려면 페이지가 로드되지않는 문제가 발생한다. 물론, 다른 /notic/ 링크로 갔다가 다시 view2로 이동하면 이동이 잘된다. 문제해결을 하기 위해 다음과 같은 시도를해봤다. 기존 view2 수정 view2 솔직히 수정 후에는 될 줄 알았는데 바보같은생각이였다. 역시나 똑같이 안됨. 그외 @click=replaceUrl(item.url) 으로 클릭 이벤트가 있을시 replac…
댓글을 사용할 수 없습니다.