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

support for nuxt3 #255

Open
frederic117 opened this issue Mar 30, 2022 · 5 comments
Open

support for nuxt3 #255

frederic117 opened this issue Mar 30, 2022 · 5 comments

Comments

@frederic117
Copy link

Doesn't seem to wrk with nuxt3

@CavalcanteLeo
Copy link

vue-observe-visibility seems to be abandoned

@PikachuEXE
Copy link

PikachuEXE commented Mar 28, 2023

Try https://www.npmjs.com/package/vue-intersection-observer ? (I just found it, haven't even read its README
Update 1: That doesn't work in nuxt 3, Trying https://www.npmjs.com/package/@lamsal-de/vue-element-in-view
Update 2: https://www.npmjs.com/package/@lamsal-de/vue-element-in-view works but less options

@Saurou
Copy link

Saurou commented Apr 21, 2023

All I did was:

  1. Install the new vue-observe-visibility @next
    yarn add vue-observe-visibility@next --dev

  2. add a vue-observe-visibility.ts file inside /plugins folder, with this code inside:

import VueObserveVisibility from 'vue-observe-visibility'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(VueObserveVisibility)
})
  1. Apply the usual to your component:
    v-observe-visibility=“visibilityChanged"

  2. Make your function in the script, for exampe adding and removing a class:

<script setup>
const visibilityChanged = (isVisible, entry) => {
  isVisible
    ? entry.target.classList.add('is-visible')
    : entry.target.classList.remove('is-visible')
}
</script>

(I did not managed to add the visibilityChanged function directly inside vue-observe-visibility.ts)

@PikachuEXE
Copy link

Confirm that it's working

More about nuxt 3 plugins:
https://nuxt.com/docs/guide/directory-structure/plugins

@jschroeter
Copy link

https://vueuse.org/core/useElementVisibility/#useelementvisibility seems to be a good alternative.

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