【问题标题】:How do you add a custom property in Vue Component with TypeScript and without TypeScript yelling?如何使用 TypeScript 在 Vue 组件中添加自定义属性,而不需要 TypeScript 大喊大叫?
【发布时间】:2020-01-27 11:12:30
【问题描述】:

请看这个最小的例子:

import Vue from 'vue';

Vue.extend({
  mounted() {
    this.something = null;
  }
});

上面的代码让 TypeScript 大喊大叫。

如果不将我的财产放到data() 财产中,我该如何解决这个问题?

【问题讨论】:

  • Vue 官方文档介绍了如何将其与 TypeScript 一起使用:vuejs.org/v2/guide/typescript.html
  • 为什么不用 vue-property-decorator 模块?
  • @jacopotaba 这是第 2 阶段,尚未完成。
  • 什么?模块?
  • @jacopotaba 装饰器语法本身,未来的 API 可能会改变。

标签: typescript vue.js


【解决方案1】:

我想通了。

将函数调用解压到外面,输入any类型。

【讨论】:

    猜你喜欢
    • 2021-12-05
    • 2021-07-30
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 2021-01-17
    • 2021-10-05
    • 2022-11-21
    相关资源
    最近更新 更多