父组件传值
<template>
<h1>列表</h1>
<hr />
<Child :total="list.length" :list="list"></Child>
</template>
<script setup lang="ts">
import Child from "./Child.vue";
import { reactive } from "vue";
let list = reactive([{ label: "语文" }, { label: "数学" }, { label: "英语" }]);
</script>
子组件接收
<template>
<div v-for="(item, index) in list" :key="index">{{ item.label }}</div>
<button @click="updateProps">增加</button>
</template>
<script setup lang="ts">
let props = defineProps({
total: Number,
list: Array,
});
const updateProps = () => {
props.list!.push({ label: "化学" });
};
</script>