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中獲取里面的值時,就報錯


免責聲明!

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



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