【问题标题】:why is minimal ts-vue template not working?为什么最小的 ts-vue 模板不起作用?
【发布时间】:2021-11-08 09:49:00
【问题描述】:
<template>
  <div>{{ keyword }}</div>
</template>

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

export default class Page extends Vue {
  private keyword = ''
}
</script>

得到错误:

属性或方法“关键字”未在实例上定义,但在渲染期间被引用。通过初始化该属性,确保此属性是反应性的,无论是在数据选项中,还是对于基于类的组件。

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: typescript vue.js ecmascript-6


【解决方案1】:

您需要应用 @Component 装饰器。

import { Vue, Component } from 'vue-property-decorator'

@Component
export default class Page extends Vue {
  private keyword = ''
}

【讨论】:

  • 宾果游戏。但是其他组件没有 @Component 装饰器,并且仍在工作,这是为什么呢?
  • 因为他们不是class,只是普通的对象。缺少太多上下文,难以深入,您需要了解更多关于 vue 和 js 的基础知识。
猜你喜欢
  • 1970-01-01
  • 2021-11-17
  • 2011-04-11
  • 1970-01-01
  • 2014-08-01
  • 1970-01-01
  • 2018-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多