vue中父組件傳數據給子組件


父組件:

<template>
    <parent>
        <child :list="list"></child> //在這里綁定list對象
    </parent>
</template>
import child from 'child.vue';
export default{
components:{child},
  data(){
  
return {
  
//父組件的數據綁定到子組件的包裹層上
  list:["haha","hehe","xixi"];
}
}

子組件:(子組件要嵌套到父組件中)

child.vue
<template>
   <ul>
        <li v-for="(item ,index)in list">{{item}}</li>
    </ul>
</template>
export default{
     props:{
    list:{
      type:Array,//type為Array,default為函數
      default(){
        return [
          "hahaxixihehe"//默認初始值
        ]}}
    }
,//用props屬性進行傳數據,此時子組件已經獲取到list的數據了 data(){ return {} } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM