动态组件在vue-cli3的typescript中使用不了

vue-cli3配置使用了typescript,动态组件使用不了,在chrome中显示不出了,控制台提示错误

Vue warn: Property or method "Hello" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
      <hello></hello>
      <component :is="Hello"></component>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator'
import Hello from './hello.vue'

@Component({
  components: {
  Hello
  }
  })
export default class HelloWorld extends Vue {
  @Prop() private msg!: string;
}
</script>
阅读 3.6k
1 个回答

because dynamic components require a variable from data, props or computed. Most likely data. So something like data() { return { component: "Hello" } }

添加下面的代码就可以了
private Hello: string = 'Hello'

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题