-
Vue 프로젝트 검색 정보 초기화 및 페이지 전환 스크롤 위치 복구프로젝트/영화 검색 (Vue) 2021. 8. 24. 19:03
Vue 프로젝트 검색 정보 초기화 및 페이지 전환 스크롤 위치 복구
1. /src/routes/index.js 수정
- scrollBehavior() 추가
... export default createRouter({ history: createWebHashHistory(), scrollBehavior() { return { top: 0 } }, routes: [ ... ] })
2. /src/store/movie.js 수정
- resetMovies() 수정
import axios from 'axios' import _uniqBy from 'lodash/uniqBy' const _defaultMessage = 'Search for the movie title!' export default { namespaced: true, state: () => ({ ... }), getters: {}, mutations: { ... }, resetMovies(state) { state.movies = [] state.message = _defaultMessage state.loading = false } ...
3. /src/routers/Home.vue 수정
- created() 추가
... export default { components: { ... }, created() { this.$store.commit('movie/resetMovies') } } ...
참고
https://next.router.vuejs.org/guide/advanced/scroll-behavior.html
Scroll Behavior | Vue Router
When using client-side routing, we may want to scroll to top when navigating to a new route, or preserve the scrolling position of history entries just like real page reload does. Vue Router allows you to achieve these and even better, allows you to comple
next.router.vuejs.org
'프로젝트 > 영화 검색 (Vue)' 카테고리의 다른 글
Vue 프로젝트 영화 정보 반환 API 만들기 (0) 2021.08.27 Vue 프로젝트 Netliyfy-CLI 구성 (0) 2021.08.26 Vue 프로젝트 Vuex Helpers (0) 2021.08.22 Vue 프로젝트 모든 컴포넌트에서 전역 스타일 가져오기 (0) 2021.08.21 Vue 프로젝트 부트스트랩 Breakpoint(반응형) (0) 2021.08.20