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 [] }    
    }      
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM