自定義彈框組件時,需要在彈框內顯示要選擇的人員列表,需要組件中的對應字段接收一個Array數組,默認返回空數組[],直接定義空數組報錯,代碼如下:
props:{ options: { type: Array, default: [] } }
提示錯誤如下:
30:9 error Type of the default value for 'options' prop must be a function vue/require-valid-default-prop
✖ 1 problem (1 error, 0 warnings)
錯誤信息提示,不能直接定義空對象的默認值,必須使用 工廠函數 return 回一個默認值。
修改代碼如下,問題解決:
props:{ options: { type: Array, default: () => [] //default: function () { return [] } } }