move composables to their own folder
This commit is contained in:
parent
62106f0d54
commit
e34f4814c8
3 changed files with 2 additions and 13 deletions
21
src/composables/useScrollPosition.js
Normal file
21
src/composables/useScrollPosition.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
export function useScrollPosition() {
|
||||
const x = ref(0)
|
||||
const y = ref(0)
|
||||
|
||||
const update = (e) => {
|
||||
x.value = window.scrollX
|
||||
y.value = window.scrollY
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('scroll', update)
|
||||
update()
|
||||
})
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('scroll', update)
|
||||
})
|
||||
|
||||
return { x, y }
|
||||
}
|
||||
18
src/composables/useWindowSize.js
Normal file
18
src/composables/useWindowSize.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
|
||||
export function useWindowSize() {
|
||||
const height = ref(0)
|
||||
const width = ref(0)
|
||||
|
||||
const update = () => {
|
||||
height.value = window.innerHeight
|
||||
width.value = window.innerWidth
|
||||
}
|
||||
|
||||
onMounted(() => window.addEventListener('resize', update))
|
||||
onUnmounted(() => window.removeEventListener('resize', update))
|
||||
|
||||
update()
|
||||
|
||||
return { height, width }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue