|
@@ -0,0 +1,49 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <h1>
|
|
|
+ Props
|
|
|
+ </h1>
|
|
|
+ <p>我叫{{name}},喜欢{{hobby}}</p>
|
|
|
+ <p>
|
|
|
+ {{score}}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { ref, reactive,withDefaults,defineProps} from 'vue'
|
|
|
+import { aaList} from '../types/demo16.ts';
|
|
|
+// 1.传什么 接什么
|
|
|
+// defineProps(['name','hobby']);
|
|
|
+// let score:aaList = reactive([
|
|
|
+// {
|
|
|
+// name:"小红",
|
|
|
+// grad: 70
|
|
|
+// },
|
|
|
+// {
|
|
|
+// name:"小白",
|
|
|
+// grad: 30
|
|
|
+// },
|
|
|
+// {
|
|
|
+// name:"小蓝",
|
|
|
+// grad: 20
|
|
|
+// }
|
|
|
+// ])
|
|
|
+// 2.规定类型
|
|
|
+// defineProps({
|
|
|
+// name:string,
|
|
|
+// hobby:string
|
|
|
+// })
|
|
|
+// const props = defineProps<{score:aaList,name:string,hobby:string}>()
|
|
|
+// console.log(props.score,'props')
|
|
|
+// 3.是否必传 + 默认
|
|
|
+// defineProps([])
|
|
|
+const props = withDefaults(defineProps<{score:aaList,name:string,hobby:string}>(), {
|
|
|
+ name:'未知用户',
|
|
|
+ hobby: '吃饭',
|
|
|
+ score:[{name:'胡',grad:0}]
|
|
|
+})
|
|
|
+</script>
|
|
|
+<style lang='scss' scoped>
|
|
|
+
|
|
|
+</style>
|