0

我有一些东西可以使用这个 npx 命令(在 PowerShell 中运行)构建我的组件:

&npx vue-cli-service build `
    --target lib `
    --formats umd-min `
    --no-clean `
    --dest $destinationFolder `
    --name $component.Name $component.FullName

然后我根据这篇文章将它们导入我的 vue 应用程序

当使用 JS 编写组件时它工作正常,但是一旦我尝试在 TS 中创建一个,我就会收到此错误:

file:7 Uncaught TypeError: Class extends value undefined is not a constructor or null
    at Module.fb15 (file:7)
    at r (file:1)
    at 8875 (file:1)
    at file:1
    at file:1
    at file:1

我的 TypeScript vue 组件非常简单:

<template>
<h1>A lovely typescript component</h1>
</template>

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

@Component({
    name: 'TypeScriptTest'
})
export default class TypeScriptTest extends Vue { }
</script>

我确实尝试过像这样导入 vue:

import Vue from 'vue'

但它没有效果

有谁知道我该如何解决这个问题?

4

1 回答 1

0

我将此行添加到我的 html 文件的顶部:

<script src="https://cdn.jsdelivr.net/npm/vue"></script>

错误消失了,我的 TypeScript 组件成功导入

这似乎不是一个理想的解决方案,但它确实有效

于 2020-07-15T16:28:06.143 回答