如何使用 TypeScript 在 Vue2.x 类组件中正确注释

问题描述

我已经通过@vue/composition-api

接受了我的项目
// main.ts
import Vue from 'vue'
import VueCompositionApi from '@vue/composition-api'

Vue.use(VueCompositionApi)

但是当在类组件中设置 setup() 时,

<template>
  <h1>{{ name }}</h1>
</template>

<script lang="ts">
import { ComputedRef,ref } from '@vue/composition-api'
import { Component,Vue } from 'vue-property-decorator'

function useName(): { name: ComputedRef<string> } {
  const name = ref('Joe')
  return { name }
}

@Component({
  setup() {
    const { name } = useName()
    return { name }
  }
})
export default class TestName extends Vue {}
</script>

我总是收到如下警告消息:

enter image description here

我知道这来自于类组件中常规 data 字段中缺少的属性定义。但是通过使用 @vue/composition-api,我们实际上不需要设置 data 属性。

有没有人知道如何解决这个问题。 ?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)