I'm trying to create a Component instance:
App.vue
import MyComponent from './components/MyCompnent.vue';
export default {
mounted() {
// The following line fails.
const vm = new MyComponent();
vm.$mount('#some-place');
}
}
and the new
line reports an error:
Uncaught TypeError: MyComponent.default is not a constructor
So how if I want to create the component?
Following is the way to register a component inside other component:
Documentation: link
Edited: How to create vm instance
If you want to initialise the vm instance, you can do it using Vue.extend. What is does is:
and one point to note here is:
You need to make changes similar to following in your code:
Try this
Script :
Html You can call your component in html like this
Finally, I found the solution myself, very simple:
The
Component
imported itself is not a constructor, but we can easily make a constructor:So the final solution is: