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

[vue-function-api] "onMounted" get called outside of "setup()" #9

Closed
Timkor opened this issue Jun 26, 2019 · 2 comments
Closed

[vue-function-api] "onMounted" get called outside of "setup()" #9

Timkor opened this issue Jun 26, 2019 · 2 comments
Labels
not-reproducible Issue cannot be reproduced by members as described

Comments

@Timkor
Copy link

Timkor commented Jun 26, 2019

I am trying to create a hook:

import { value, computed, watch, onMounted } from 'vue-function-api';

export function useIntersectionObserver() {

    let intersectionObserver;

    const entry = value({});

    const callback = (entries) => {
        if (entries.length > 0) {
            entry.value = entries[entries.length - 1];
        }
    };

    onMounted(() => {
        intersectionObserver = new IntersectionObserver(callback);
        ...
    });

    onUnmounted(() => {
        intersectionObserver.disconnect();
    });

    return {
        isIntersecting: computed(() => entry.isIntersecting)
    };
}

And use that in some component:

  import { value, computed, watch, onMounted } from 'vue-function-api';
  import useIntersectionObserver from '...';

  export default {
    setup() {

      useIntersectionObserver();
    }
  }

Yet, I get the error:

[vue-function-api] "onMounted" get called outside of "setup()" 

Why is that, and how can I prevent this?

@liximomo
Copy link
Member

Sorry. Can't reproduce it. https://codepen.io/liximomo/pen/KjXXBY?editors=1011

@Timkor
Copy link
Author

Timkor commented Jun 26, 2019

I use it at SSR (nuxt.js). Might be the cause? I'll provide a reproduction link tomorrow.

@liximomo liximomo added the not-reproducible Issue cannot be reproduced by members as described label Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-reproducible Issue cannot be reproduced by members as described
Projects
None yet
Development

No branches or pull requests

2 participants