[英]Vue 3 Typescript props: [Vue warn]: Invalid prop: type check failed for prop "organisation". Expected Null | Boolean, got Object
[英]Vue TypeScript Object prop type is not correct
在 TypeScript(使用 Vue CLI 3 生成)中的 Vue 單文件組件中使用 Object 屬性時,道具的類型不正確,如下面的最小示例所示。
this.product
的類型是(() => any) | ComputedOptions<any>
(() => any) | ComputedOptions<any>
。 有誰知道解決這個問題?
<script lang="ts">
import Vue, { PropType } from 'vue';
interface ProductInterface {
units: number;
}
export default Vue.extend({
name: 'Product',
props: {
product: {
type: Object as PropType<ProductInterface>,
required: true,
},
},
computed: {
unitsString() {
return `${this.product.units} Units`;
},
},
});
</script>
您是否嘗試像這樣在計算屬性之后放置一個類型?
unitsString() :string{
return ...
}
Typescript 與 Vue 對推斷的計算屬性做出奇怪的反應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.