728x90
vue에서 윈도우 사이즈 변경될때마다 윈도우 사이즈를 가져오고싶은데 구글링을 아무리 해봐도 원하는 결과가 나오지 않았는데 좀더 구글링 해서 찾았다!
router/index.js 에 추가해주고 사용할때는 $viewport.width 로 사용하면 width값을 가져올 수 있다!
// router/index.js
const updateSizes = (obj = {}) => {
obj.width = window.innerWidth
obj.height = window.innerHeight
return obj
}
Object.defineProperty(Vue.prototype, '$viewport', {
value: Vue.observable(updateSizes())
})
window.addEventListener('resize', (e) => {
updateSizes(Vue.prototype.$viewport)
})
728x90
'FRAMEWORK > VUE' 카테고리의 다른 글
ubuntu20.04 + nginx + vue 로 환경설정하기 (0) | 2021.07.21 |
---|---|
vue infinite loading 활용하기 (0) | 2021.04.15 |
[vuejs]regeneratorruntime is not defined vue async 에러 해결 (0) | 2021.01.19 |
[vue.js] ckeditor4 사용하기 (0) | 2021.01.13 |
open_now is deprecated as of November 2019. Use the isOpen() method from a PlacesService.getDetails() result instead. (0) | 2020.11.23 |