【问题标题】:VueJS + TypeScript decorator issueVueJS + TypeScript 装饰器问题
【发布时间】:2019-05-11 07:06:18
【问题描述】:

我在使用 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
  • node v11.3.0 (with brew)
  • npm 6.4.1
  • yarn 1.12.3 (with 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

我在任何地方都没有找到有关此问题的任何信息。

它是从哪里来的?

感谢您的帮助!

【问题讨论】:

标签: typescript vue.js vue-cli


【解决方案1】:

尝试从 vue 导入 Vue ... 喜欢:

import Vue from 'vue';
@Component
export default class HelloWorld extends Vue {
  @Prop() private msg!: string;
}

【讨论】:

    猜你喜欢
    • 2021-03-29
    • 2021-01-14
    • 2019-07-29
    • 2016-10-05
    • 2011-05-18
    • 2021-07-07
    • 2018-06-08
    • 2019-02-23
    相关资源
    最近更新 更多