Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue3 comptible #27

Open
markusand opened this issue Aug 3, 2021 · 4 comments
Open

Vue3 comptible #27

markusand opened this issue Aug 3, 2021 · 4 comments

Comments

@markusand
Copy link

Vue 3 has been in the party for quite a long time now. Is there a plan to migrate it to Vue 3 composition API?

@superdiazzz
Copy link

i hope someone updated for vue 3

@jbrundagejr
Copy link

Is it me or is vue-scrollama incompatible with Vue3?

@attharmirza
Copy link

Hey all, I tried making a Vue 3 implementation of scrollama and it seems to work alright so far. I hope the following helps anyone who might be struggling:

<script setup>
import { ref, onUpdated } from 'vue'
import scrollama from 'scrollama'

const props = defineProps({
    offset: {
        type: [Number, String],
        required: false,
        default: () => 0.5
    },
    progress: {
        type: Boolean,
        required: false,
        default: () => false
    },
    threshold: {
        type: Number,
        required: false,
        default: () => 4
    },
    once: {
        type: Boolean,
        required: false,
        default: () => false
    },
    debug: {
        type: Boolean,
        required: false,
        default: () => false
    }
})

const parent = ref(null)

const scroller = scrollama()

const emit = defineEmits(['step-progress', 'step-enter', 'step-exit'])

onUpdated(() => {
    scroller.destroy()

    const { offset, progress, threshold, once, debug } = props

    const step = [...parent.value.children]

    scroller
        .setup({ step, offset, progress, threshold, once, debug})
        .onStepEnter(resp => {
            // console.log(resp)
            emit('step-enter', resp);
        })
        .onStepProgress(resp => {
            // console.log(resp)
            emit('step-progress', resp)
        })
        .onStepExit(resp => {
            // console.log(resp)
            emit('step-exit', resp);
        })
})
</script>

<template>
    <div ref="parent">
        <slot></slot>
    </div>
</template>

<style module></style>

@Kakedev21
Copy link

Hey all, I tried making a Vue 3 implementation of scrollama and it seems to work alright so far. I hope the following helps anyone who might be struggling:

<script setup>
import { ref, onUpdated } from 'vue'
import scrollama from 'scrollama'

const props = defineProps({
    offset: {
        type: [Number, String],
        required: false,
        default: () => 0.5
    },
    progress: {
        type: Boolean,
        required: false,
        default: () => false
    },
    threshold: {
        type: Number,
        required: false,
        default: () => 4
    },
    once: {
        type: Boolean,
        required: false,
        default: () => false
    },
    debug: {
        type: Boolean,
        required: false,
        default: () => false
    }
})

const parent = ref(null)

const scroller = scrollama()

const emit = defineEmits(['step-progress', 'step-enter', 'step-exit'])

onUpdated(() => {
    scroller.destroy()

    const { offset, progress, threshold, once, debug } = props

    const step = [...parent.value.children]

    scroller
        .setup({ step, offset, progress, threshold, once, debug})
        .onStepEnter(resp => {
            // console.log(resp)
            emit('step-enter', resp);
        })
        .onStepProgress(resp => {
            // console.log(resp)
            emit('step-progress', resp)
        })
        .onStepExit(resp => {
            // console.log(resp)
            emit('step-exit', resp);
        })
})
</script>

<template>
    <div ref="parent">
        <slot></slot>
    </div>
</template>

<style module></style>

does this also work in typescript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants