原文地址

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

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 {} } }

返回目录

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄