【问题标题】:error TS2339: Property '_componentTag' does not exist错误 TS2339:属性“_componentTag”不存在
【发布时间】:2019-11-10 00:08:04
【问题描述】:

我用 Vue、Typescript 和 Jest 编写了一个单元测试。我想得到_componentTag,但出现以下错误。我该如何解决这个问题?

错误:

error TS2339: Property '_componentTag' does not exist on type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<string, any>>'.

    21       const noSsr = wrapper.vm.$children[0].$options._componentTag;
                                                            ~~~~~~~~~~~~~       

【问题讨论】:

    标签: typescript unit-testing vue.js jestjs vue-component


    【解决方案1】:

    _componentTag 是内部属性,不是公共 API 的一部分。

    可以通过禁用类型检查来访问:

    wrapper.vm.$children[0].$options['_componentTag'];
    

    【讨论】:

      猜你喜欢
      • 2019-01-21
      • 2016-08-13
      • 2017-12-20
      • 2020-12-28
      • 2016-11-14
      • 2017-10-24
      • 2021-08-10
      • 2018-11-17
      • 2020-09-25
      相关资源
      最近更新 更多