-
Vue 프로젝트 영화 목록 ID 중복 제거프로젝트/영화 검색 (Vue) 2021. 8. 3. 06:00
Vue 프로젝트 영화 목록 ID 중복 제거
1. npm i lodash
2. /src/store/movie.js 수정
- 영화 목록 ID 중복 제거 코드 작성 ( lodash _uniqBy() 사용 )
import axios from 'axios' import _uniqBy from 'lodash/uniqBy' export default { ... 생략 commit('updateState', { movies: _uniqBy(Search, 'imdbID') }) // 추가 요청 if (pageLength > 1) { ...생략 commit('updateState', { movies: [ ...state.movies, ..._uniqBy(Search, 'imdbID')] }) } } } } }
참고
https://lodash.com/docs/4.17.15#uniqBy
Lodash Documentation
_(value) source Creates a lodash object which wraps value to enable implicit method chain sequences. Methods that operate on and return arrays, collections, and functions can be chained together. Methods that retrieve a single value or may return a primiti
lodash.com
'프로젝트 > 영화 검색 (Vue)' 카테고리의 다른 글
Vue 프로젝트 영화 아이템 - 기본 출력 (0) 2021.08.06 Vue 프로젝트 영화 검색 코드 리팩토링 (0) 2021.08.06 Vue 프로젝트 영화 검색 추가 요청 (0) 2021.08.03 Vue 프로젝트 영화 검색 (0) 2021.08.02 Vue 프로젝트 Vuex(Store) 구성 (0) 2021.08.02