<template>
<div class="about">
<h1>Today is not easy,</h1>
<h1>Tomorrow is more difficult,</h1>
<h1>But the day after tomorrow will be wonderful!</h1>
<Child :info="info || {}"/>
</div>
</template>
<script>
import Child from './components/Child.vue'
export default {
components: { Child },
data () {
return {
// 当info传的是null或者undefined时,控制台会报错,传空对象倒不会出错
info: null
}
}
}
</script>
子组件Child.vue
<template>
<div>{{ info.school }}</div>
</template>
<script>
export default {
name: 'Child',
props: {
info: {
type: Object,
required: true
}
},
data () {
return {
}
}
}
</script>
<style>
</style>