프로젝트/영화 검색 (Vue)
Vue 프로젝트 영화 목록 ID 중복 제거
IT Blue
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