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

Error: [vue-function-api] "onCreated" get called outside of "setup()" #38

Closed
wcldyx opened this issue Jul 25, 2019 · 1 comment
Closed

Comments

@wcldyx
Copy link

wcldyx commented Jul 25, 2019

The hook is not working properly

import {value, computed, watch, onMounted, onDestroyed, onCreated, state, createComponent} from 'vue-function-api';
    import Vue from 'vue';

    const MessageComponent = {
        setup() {
            const msg = value('hello');
            onMounted(() => console.log('hello'));
            return {
                msg
            };
        }
    };
    export default createComponent({
        setup() {
            const Message = Vue.extend(MessageComponent);
            const message = new Message();
            onCreated(() => console.log('create message'));
            return {};
        }
    });

Error: [vue-function-api] "onCreated" get called outside of "setup()"

@LinusBorg
Copy link
Member

LinusBorg commented Jul 30, 2019

Manually creating a component instance like that in setup will break this plugin, correct.

In a way it's expected behaviour, as calling new Message() made this component the currentInstance, so now all hooks expect to be called within this instance's setup function.

The proper way to handle that would probably be to create that instance within a hook like oncreated(), not within setup()`, but I'm not sure if that works for your situation.

So can you provide a bit of context for the use case that you have for this?

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

2 participants