I am using
vue-class-component
.vue
hello.vue
vue-class-component
<template></template>
<script lang="ts">
import Vue from 'vue'
import Component from 'vue-class-component'
@Component({
})
export default class Hello extends Vue {
created() {
console.log("I am created!")
}
}
</script>
import Hello from "./components/hello.vue"
let v = new Vue({
el: "#app",
template: `<div><hello></hello></div>`,
components: {Hello},
created : function(){
console.log("root instance created")
}
});
<template><hello></hello></template>
<script lang="ts">
import Vue from 'vue'
import Component from 'vue-class-component'
import Hello from "./components/hello.vue"
@Component({
el: "#app",
components: {Hello}
})
export default class App extends Vue {
created() {
console.log("created the root instance")
}
}
</script>
import Vue from "vue"
import App from "./components/app.vue"
let vm = new Vue(App)
App
Argument of type 'typeof Vue' is not assignable to parameter
of type 'ComponentOptions<Vue> | undefined'
The components
section of an options object can specify components by spec or (apparently, I can't find this in the documentation) by including the component itself.
The Vue
constructor does not accept a component, it requires a spec. Since a component is already an extension of Vue
, so there's no reason to try to run it back through the Vue
constructor. Just say
let vm = new App();