Vue自定義組件Props中接收數組

問題

報錯

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

報錯信息

[Vue warn]: Invalid default value for prop "showcontent": Props with type Object/Array must use a factory function to return the default value.

問題解決

props: {
    showcontent: {
      type: Array,
      default: function () { return [] }
    },
}

ES6

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

Vue自定義組件Props中接收數組

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章