关于vue中props接收的几种写法 - Type of the default value for ‘minetlist‘ prop must be a function

父组件中传值:

 <mineConponent :minetlist="mineList" />

子组件接收:

  1. 第一种写法:直接使用 props 以一维数组的方式接收
	props: ['minetlist']
  1. 第二种写法:使用对象形式接收,并赋予默认值,但是在数组这里接收有问题,一个大坑,请看第三种
 props: {
    
    
    minetlist: {
    
    // 数组这里接收有问题,请看第三种
      type: Array, // 类型
      default: [] // 默认值
    },
     minetom: {
    
    
      type: Number,
      default: 0
    }
  },
  1. 第三种写法:接收数组,是需要以函数形式接收
 props: {
    
    
    minetlist: {
    
    
      type: Array,
      default: function () {
    
    
        return []
      }
    }
  },

猜你喜欢

转载自blog.csdn.net/m0_46442996/article/details/110236330
今日推荐