一、父組件給子組件傳值
步驟1:調用子組件的時候給子組件綁定動態屬性;
<v-son v-bind:hahaha="title2"></v-son>
步驟2:子組件接收父組件的傳值,就是在子組件裏面跟data和methods的平級加入props;
<template> <div class="son"> 這個是子組件,引入父組件的titlt---{{hahaha}} </div> </template> <script> export default { name: "SonComponents", data(){ return {} }, props: ['hahaha'] } </script>
步驟3:直接在子組件中使用。
注意:給引入的子組件綁定的可以是自定義屬性。
如果父組件傳給子組件的擁有同名,則默認使用父組件的數據,不建議同名