Vue props中Object和Array设置默认值

Vue中,在props中设置Object和Array的默认值

seller: {
   type: Object,
   default() {
      return {}
   }
}
seller: {
   type: Object,
   default: function () {
       return {}
  }
}

当父组件没有传这个值或者值是空时,输出的话,返回:

下面这种是错误的

seller: {
    type: Object,
    default: () => {}
}

当父组件没有传这个值或者值是空时,输出的话,这时是返回underfind,在template中获取里面的值时,就报错

原文地址:https://www.cnblogs.com/zhaobao1830/p/10939071.html