Invalid default value for prop 'XXX': props with type object/array must use a factory function to return the default value

vue组件在props中 给默认值的时候  容易出现这个错误。

解决办法:

default 给默认值是object/array 类型的时候,应该使用function函数return返回默认值:

错误写法:

props:{
  files:{
    type:Array,
    default:[]    
    }      
}

正确写法:

props:{
  files:{
    type:Array,
    default:()=>{ return [] }    
    }      
}

 

posted @ 2022-04-06 10:39  &执念  阅读(824)  评论(0编辑  收藏  举报