<script setup lang="ts">
defineProps<{
msg: string,
student: {
name: string,
age: number,
},
students: {
name: string,
age: number,
}[]
}>()
</script>
<template>
<h1>简单传值:{{ msg }}</h1>
<h1>传对象:{{ student }}</h1>
<h1>传数组第一个值:{{ students[0] }}</h1>
<h1>传数组第二个值:{{ students[1] }}</h1>
</template>
<style scoped>
</style>
// 接收父组件传参,带默认值
const props = withDefaults(defineProps<{
row?: DocSend,
isEdit?: boolean
}>(), {
row: undefined,
isEdit: false
});
<template>
<Hello msg="訾博" :student="student" :students="students" />
</template>
<script setup lang="ts">
import Hello from "./components/Hello.vue";
// 对象
const student = {
name: "訾博",
age: 26,
};
// 对象数组
const students = [
{
name: "訾博1",
age: 26,
},
{
name: "訾博2",
age: 26,
},
];
</script>
1、父组件中的响应式属性的值被修改后,该属性在子组件中的值也会被修改;
2、子组件中使用 const props = defineProps<{ msg: string }>()
定义接收的属性,可以直接访问,也可以通过 props
访问;
3、子组件中使用 const props = defineProps<{ msg: string }>()
定义接收的属性,子组件中的 props.msg
的值不是响应式的,是只读的,无法修改;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有