如何在带有Typescript的视图中使用Vue单个文件组件?

问题描述

我尝试了很多方法,并且总是会遇到某种构建或运行时错误我有些惊讶,但是经过大量搜索之后,我仍然找不到合适的示例或有关此的帖子。我使用Vue UI使用Typescript创建了一个新项目,然后创建了以下组件:

<template>
  <div class="navigation">
    BACK | NEXT buttons go here
  </div>
</template>

<script lang="ts">
import { Component,Vue } from "vue-property-decorator";

@Component
export default class BackNext extends Vue {
}
</script>

接下来,我尝试在.vue视图文件中使用此组件,并且该组件与我所获得的组件差不多:

<template>
  <div class="question">
    <h1>Personal</h1>
    <back-next />
  </div>
</template>
<script lang="ts">
import { Component,Vue } from "vue-property-decorator";
import BackNext from "../../components/BackNext.vue";
@Component
export default class Personal extends Vue {
  components = {
    'back-next': BackNext
  }
}
</script>

但这失败,并出现以下构建错误

 ERROR  Failed to compile with 11 errors4:22:27 PM

These dependencies were not found:

* core-js/modules/es.object.get-prototype-of in ./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js
* core-js/modules/es.object.to-string in ./node_modules/@babel/runtime/helpers/esm/isNativeReflectConstruct.js,./node_modules/@babel/runtime/helpers/esm/typeof.js
* core-js/modules/es.reflect.construct in ./node_modules/@babel/runtime/helpers/esm/createSuper.js,./node_modules/@babel/runtime/helpers/esm/isNativeReflectConstruct.js
* core-js/modules/es.regexp.to-string in ./node_modules/@babel/runtime/helpers/esm/isNativeReflectConstruct.js
* core-js/modules/es.string.iterator in ./node_modules/@babel/runtime/helpers/esm/typeof.js
* core-js/modules/es.symbol in ./node_modules/@babel/runtime/helpers/esm/typeof.js
* core-js/modules/es.symbol.description in ./node_modules/@babel/runtime/helpers/esm/typeof.js
* core-js/modules/es.symbol.iterator in ./node_modules/@babel/runtime/helpers/esm/typeof.js
* core-js/modules/web.dom-collections.iterator in ./node_modules/@babel/runtime/helpers/esm/typeof.js

To install them,you can run: npm install --save core-js/modules/es.object.get-prototype-of core-js/modules/es.object.to-string core-js/modules/es.reflect.construct core-js/modules/es.regexp.to-string core-js/modules/es.string.iterator core-js/modules/es.symbol core-js/modules/es.symbol.description core-js/modules/es.symbol.iterator core-js/modules/web.dom-collections.iterator

目前尚不清楚启用了Typescript支持的标准新项目是否需要安装一些依赖项才能使用一些非常标准的功能,我不想通过安装大量依赖项来进一步弄乱我的项目可能需要或不需要的东西。

npm版本6.13.4

节点版本12.16.1

纱线版本​​1.22.4

vue版本@ vue / clu 4.5.3

解决方法

您需要在装饰器中注册

24120336