MilkshakeStudio / nuxt-lenis

Nuxt adaptation for @darkroomengineering/lenis
https://github.com/darkroomengineering/lenis
30 stars 4 forks source link

Reactive variables binding doesn't work #3

Closed Confringe closed 5 months ago

Confringe commented 11 months ago

Hello, I'm currently trying to bind a reactive variable to the current scroll state, using lenis in a Nuxt 3 project. But for some reason it doesn't work as soon as I use that variable in another reactive context, e.g. display it to the user. When I simply print the variable in the console it works just fine. E.g. watch(somevar, ...) also doesn't work. I have investigated the issue further and found out, that the onscroll hook gets removed after the first function call, thus not only doesn't the variable get updated further, but the function doesn't get called at all. I have tried to manually set the hook after it has been removed, but it just gets removed again. I have boiled the issue down to the following minimal app.vue example:

<template>
    <lenis @scroll="scrollEmitter">
    <div style="height: 200vh;">
        {{ somevalue }}
    </div>
    </lenis>
</template>

<script setup>
const somevalue = ref(0)

const scrollEmitter = (val) => {
    console.log(val.animate.value)
    somevalue.value = val.animate.value
}
</script>

I am using Nuxt 3.7.4 and nuxt-lenis 1.0.3. Some help would be much appreciated!

Slgoetz commented 9 months ago

I will take a look at this, however, you can use const scrollState = inject("scrollState"); and then watch scrollState if you want to do something on scroll

Slgoetz commented 5 months ago

@Confringe I am closing this issue since there was never a response.