typescript - VueJS + TypeScript 装饰器问题
问题描述
我在使用 vue-cli 创建新应用时遇到了一个奇怪的问题:HelloWorld 组件的装饰器有错误。我没有接触任何东西,所有的代码和配置都来自 vue-cli。
这是错误:
ERROR in /Users/JohnSmith/test/src/components/HelloWorld.vue
37:1 Unable to resolve signature of class decorator when called as an expression.
Type '<VC extends VueClass<Vue>>(target: VC) => VC' is missing the following properties from type 'typeof HelloWorld': extend, nextTick, set, delete, and 7 more.
35 | import { Component, Prop, Vue } from 'vue-property-decorator';
36 |
> 37 | @Component
| ^
38 | export default class HelloWorld extends Vue {
39 | @Prop() private msg!: string;
40 | }
我找到了这个解决方法:
@Component({
props: {
msg: {type: String},
},
})
export default class HelloWorld extends Vue {
// @Prop() private msg!: string;
}
但是我想使用装饰器,生成的虚拟项目出现错误是不正常的。
这是我的环境:
- macOS High Sierra 10.13.6
- 节点 v11.3.0(带 brew)
- npm 6.4.1
- 纱线 1.12.3(带 brew)
- Vue CLI v3.2.1
- 酿造医生很好
以下是我用于创建项目的 vue-cli 选项:
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, TS, PWA, Router, Vuex, CSS Pre-processors, Linter
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript for auto-detected polyfills? Yes
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS
? Pick a linter / formatter config: TSLint
? Pick additional lint features: (Press <space> to select, <a> to toggle all, <i> to invert selection)Lint on save
? Where do you prefer placing config for Babel, PostCSS, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No
我在任何地方都没有找到有关此问题的任何信息。
它是从哪里来的?
谢谢你的帮助!
解决方案
尝试从 vue 导入 Vue ... 比如:
import Vue from 'vue';
@Component
export default class HelloWorld extends Vue {
@Prop() private msg!: string;
}
推荐阅读
- java - Amazon Elastic Transcoder 无法使用 MD5=wJForaVS6T5wok/80E4RYg== 解密加密密钥
- spring-webflux - Spring WebClient:解析+流非常大的JSON
- saml - 在 shibboleth SP 中签署身份验证请求
- kubernetes - 在 2 个虚拟机上创建集群拆分的解决方案
- android - 颤振:自定义字体显示没有效果
- scala - 如何将序列函数应用于猫的 ValidatedNel 列表?
- python - 如何编写一个函数,在 Python 中递归生成一个向量?
- c# - 调用默认构造函数时如何使用 ApplicationUserManager?
- matrix - 计算由 SSRS 中的矩阵生成的值
- c# - 具有现有 CosmosDB 404 错误的实体框架核心