vue父组件如何向子组件中传递数据?


原文地址


 

props传参

父组件:

<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