缺少类型 'ObjectConstructor' 中的以下属性:prototype、getPrototypeOf、getOwnPropertyDescriptor、getOwnPropertyNames 以及其他 18 个
missing the following properties from type 'ObjectConstructor': prototype, getPrototypeOf, getOwnPropertyDescriptor, getOwnPropertyNames, and 18 more
我正在使用 Vue.js 并且我正在尝试将我的对象分配给一个字段但是它收到以下错误
(property) _bodyContent: ObjectConstructor
Type 'GameComponent' is missing the following properties from type 'ObjectConstructor': prototype, getPrototypeOf, getOwnPropertyDescriptor, getOwnPropertyNames, and 18 more.Vetur(2740)
Html 在我的 Vue 组件中。
<v-tab v-for="(components, i) in $data._multiComponent.components" :key="i" @click="onTabClick(i)">
{{i + 1}}
</v-tab>
我的 Vue 组件中的脚本。 Vscode 显示错误在赋值左侧的 onTabClick 中。
<script lang="ts">
import Vue, { PropOptions } from "vue";
import MultiComponent from "~/ts/interfaces/game_components/multi_component";
import GameComponent from "~/ts/interfaces/game_components/game_component";
export default Vue.extend({
props: {
multiComponent: {
type: Object,
required: true,
} as PropOptions<MultiComponent>,
},
data() {
return {
_multiComponent: this.multiComponent,
_componentEnabled: true,
_bodyContent: Object,
};
},
methods: {
onTabClick(index:number)
{
this._bodyContent = this._multiComponent.components[index];
},
}
});
</script>
多组件界面
import './game_component';
import GameComponent from './game_component';
export default interface GameMultiComponent{
title:String;
isEnabled:Boolean;
components:Array<GameComponent>;
}
游戏组件接口
export default interface GameComponent{
title:String;
isEnabled:Boolean;
}
我还可以使用 GameComponent 作为我的字段类型而不是 Object 吗?我该怎么做?
data() {
return {
......
_bodyContent: Object, // you ascribe type Object to _bodyContent here
};
},
然后您将其等同于 this._multiComponent.components[index]
,您将其归为类型 Array<GameComponent>
export default interface GameMultiComponent{
components:Array<GameComponent>; // you ascribe Array<GameComponent> to components here
}
改为
data() {
return {
......
_bodyContent: this._multiComponent.components[0] as GameComponent , // you ascribe type Object to _bodyContent here
};
},
这应该可以解决问题。
我正在使用 Vue.js 并且我正在尝试将我的对象分配给一个字段但是它收到以下错误
(property) _bodyContent: ObjectConstructor
Type 'GameComponent' is missing the following properties from type 'ObjectConstructor': prototype, getPrototypeOf, getOwnPropertyDescriptor, getOwnPropertyNames, and 18 more.Vetur(2740)
Html 在我的 Vue 组件中。
<v-tab v-for="(components, i) in $data._multiComponent.components" :key="i" @click="onTabClick(i)">
{{i + 1}}
</v-tab>
我的 Vue 组件中的脚本。 Vscode 显示错误在赋值左侧的 onTabClick 中。
<script lang="ts">
import Vue, { PropOptions } from "vue";
import MultiComponent from "~/ts/interfaces/game_components/multi_component";
import GameComponent from "~/ts/interfaces/game_components/game_component";
export default Vue.extend({
props: {
multiComponent: {
type: Object,
required: true,
} as PropOptions<MultiComponent>,
},
data() {
return {
_multiComponent: this.multiComponent,
_componentEnabled: true,
_bodyContent: Object,
};
},
methods: {
onTabClick(index:number)
{
this._bodyContent = this._multiComponent.components[index];
},
}
});
</script>
多组件界面
import './game_component';
import GameComponent from './game_component';
export default interface GameMultiComponent{
title:String;
isEnabled:Boolean;
components:Array<GameComponent>;
}
游戏组件接口
export default interface GameComponent{
title:String;
isEnabled:Boolean;
}
我还可以使用 GameComponent 作为我的字段类型而不是 Object 吗?我该怎么做?
data() {
return {
......
_bodyContent: Object, // you ascribe type Object to _bodyContent here
};
},
然后您将其等同于 this._multiComponent.components[index]
,您将其归为类型 Array<GameComponent>
export default interface GameMultiComponent{
components:Array<GameComponent>; // you ascribe Array<GameComponent> to components here
}
改为
data() {
return {
......
_bodyContent: this._multiComponent.components[0] as GameComponent , // you ascribe type Object to _bodyContent here
};
},
这应该可以解决问题。