Today marks my inaugural experience with VueJS, as we delve into a class project utilizing TypeScript. The task at hand is to transfer the attributes of the tabsData variable from the parent component (the view) to the child (the view component). Allow me to present you with the code snippet:
<script setup lang="ts">
//import { reactive, ref, computed } from "vue";
import ArgumentTabComponent from "./components/ArgumentTabComponent.vue";
import $t from "@/core/utils/i18n/translate";
import Button from "primevue/button";
import type { IntArgumentListData } from "./types/IntArgumentListData";
const tabsData: IntArgumentListData[] = [
{
title: "Argumento 1",
content: "texto1",
},
{
title: "Argumento 2",
content: "texto2",
},
{
title: "Argumento 3",
content: "texto3",
},
{
title: "Argumento 4",
content: "texto4",
},
{
title: "Argumento 5",
content: "texto5",
},
];
const handleRedirect = () => {
alert("Aceptando!");
};
</script>
<template>
<br />
<h1>Argumentarios</h1>
<div class="">
<ArgumentTabComponent> {{ tabsData }}</ArgumentTabComponent>
<hr />
<Button :label="$t('common.accept')" @click="handleRedirect" />
</div>
</template>
Extensive research on the internet and YouTube failed to provide much insight due to the use of export default {} being incompatible with TypeScript. In an attempt to pass properties, I employed the following approach:
<script setup lang="ts">
import TabView from "primevue/tabview";
import TabPanel from "primevue/tabpanel";
// Lib imports
//import { ref } from "vue";
import type { IntArgumentListData } from "../types/IntArgumentListData";
// Properties
const props = defineProps<{
title: IntArgumentListData;
content: IntArgumentListData;
}>();
</script>
<template>
<br />
<div class="">
<TabView>
<TabPanel v-for="tab in props" :key="tab.title" :header="tab.title">
<p>{{ tab.content }}</p>
</TabPanel>
</TabView>
</div>
<br />
</template>
Unfortunately, this method resulted in a perplexing error within the parent component:
Facing this challenge has left me disoriented. Despite countless hours dedicated to experimentation and contemplation, I am unable to decipher my missteps. Your assistance is greatly appreciated.
Error message in English:
The type '{ tabData: IntArgumentListData[]; "tab data": IntArgumentListData[]; }' cannot be assigned to type 'IntrinsicAttributes & Partial<{}> & Omit<Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ tabsData: IntArgumentListData[]; }>>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>'. Property "tabsData" is missing in type "{ tabData: IntArgumentListData[]; "tab-data": IntArgumentListData[]; }", but is required in type "Omit<Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{ tabsData: IntArgumentListData[ ]; }>>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>".ts(2322)