"预期对象,得到了承诺。"承诺作为道具传递时的错误

时间:2018-03-06 08:59:10

标签: javascript typescript vue.js vuejs2

我只是尝试将Promise作为Prop传递给期望Promise的子组件但是我有一个错误告诉期望的类型是Object。

我使用TypeScriptvue-property-decoratorvue-class-component作为我的项目。

我的代码如下所示:

<template>
  <child-component :listPromise="listAsPromise"/>
</template>

<script lang="ts">
import { Component, Vue, Prop, Inject } from 'vue-property-decorator'
import  { EditableReferentielModel } from '@/api/model/referentiel'
import ReferentielResource from '@/api/resources/referentiel'
import { AxiosResponseExt } from '@/api/resources/index'

export default class ParentComponent extends Vue {
  @Inject()
  referentielResource: ReferentielResource

  listAsPromise: Promise<EditableReferentielModel[] & AxiosResponseExt> = this.referentielResource.getStadeDeveloppement()
}

</script>
<script lang="ts">
import { Component, Vue, Prop, Inject } from 'vue-property-decorator'
import ReferentielResource from '@/api/resources/referentiel'
import { EditableReferentielModel } from '@/api/model/referentiel'
import { AxiosResponseExt } from '@/api/resources/index'

@Component
export default class ChildComponent extends Vue {
  @Inject()
  referentielResource: ReferentielResource

  @Prop({ default: null })
  value: EditableReferentielModel | null
  @Prop({ default: null })
  listPromise: Promise<EditableReferentielModel[] & AxiosResponseExt>

  referentiel: EditableReferentielModel[] = []
  selected: EditableReferentielModel | null = this.value

  async mounted () {
    this.referentiel = await this.listPromise
  }
}
</script>

使用此代码,即使[Vue warn]: Invalid prop: type check failed for prop "listPromise". Expected Object, got Promise.类型设置为listPromise,我仍然会收到此错误:any

有什么问题?

0 个答案:

没有答案