1、App.vue程式碼如下:
<template> <Father/> </template> <script setup> import Father from './view/Father.vue' </script> <style> </style>
2、Father.vue程式碼如下:
<template> <h3>父頁面</h3> <Child :title="msg"/> </template> <script> import Child from './Child.vue' export default { data() { return { msg: '父頁面資料!' } }, components: { Child } } </script> <style scoped> </style>
3、Child程式碼如下:
<template> <h3>子頁面</h3> <p>{{ title }}</p> </template> <script> export default { data() { return {} }, props: ['title'] } </script> <style scoped> </style>
4、效果如下: