Vue——[Props with type Object/Array must use a factory function to return the default value.]解决方案
生活随笔
收集整理的這篇文章主要介紹了
Vue——[Props with type Object/Array must use a factory function to return the default value.]解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題描述
[Vue warn]: Invalid default value for prop "weekTable": Props with type Object/Array must use a factory function to return the default value.官方文檔
https://cn.vuejs.org/v2/guide/components-props.html
問題分析
Prop“值”的默認缺省值:Type對象/數組的PROPS必須使用工廠函數返回默認值。
如果參數類型是 Array 或 Object ,默認值必須是由工場函數返回,不能直接賦值。
解決方案
錯誤代碼:
proE: {type: Array,default: [] }正確代碼:
proE: {type: Array,default: () => [] }注意事項:當是 Object 類型時,而且又使用 箭頭函數時,如果設置默認值為空對象,必須加上括號
錯誤代碼:
proE: {type: Object,default: () => {} }正確代碼:
proE: {type: Object,default: () => ({}) }參考文章
https://www.cnblogs.com/qdjl/p/9487236.html
https://www.cnblogs.com/similar/p/10571257.html
總結
以上是生活随笔為你收集整理的Vue——[Props with type Object/Array must use a factory function to return the default value.]解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Element UI——滚动条组件(El
- 下一篇: JavaScript——判断undefi