Skip to content

Retrieving an encapsulated component #348

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

Closed
ayamflow opened this issue Jul 10, 2014 · 3 comments
Closed

Retrieving an encapsulated component #348

ayamflow opened this issue Jul 10, 2014 · 3 comments

Comments

@ayamflow
Copy link

Hello,
5 months in and still loving Vue :)

I just stumbled upon something: I have registered & encapsulated some private components into a vm. Some of them are created via the DOM with v-component. Some others need to be created procedurally. I tried this:

var TheComponent = Vue.component('the-component');
var component = new TheComponent({....});

but Vue.component(id) returns undefined. Is this possible at the moment ?

Also, I remember this issue from @bpierre, is there a specific way to instanciate a given component without having to retrieve it first ?

@yyx990803
Copy link
Member

How did you encapsulate it? With Vue.extend?

@ayamflow
Copy link
Author

Oops, forgot to put this fiddle. I used the components instantiation option like this:

// the-component.js
module.exports = {
    template: require('./the-component.html'),
    ....
};

// index.js
var root = new Vue({
    components: {
        'the-component': require('./the-component');
   }
});

@ayamflow
Copy link
Author

I dug into the source and found out that the private components are stored into the $options hash.
My fix is then:

var TheComponent = this.$options.components['the-component'];
var theComponent = TheComponent.extend({...});
theComponent.$appendTo(this.$el);

Interested to know if there is a shorter way though !

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