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.

問題描述

調試圖片今天在學習小馬哥的購物車demo時發生該問題,翻譯下標藍的提示信息,我們可以知道如果props類型爲Object/Array 則use a factory function to return the default value,同時網上也有參考大佬們的解決辦法,在此記錄下

解決辦法

    // 報錯代碼
    props: {
		cartList: {
			type: Array,
			default:[]
		}
	},
    // 正解1   箭頭函數
    props: {
		cartList: {
			type: Array,
			default:()=>[]
		}
	}
    // 正解2
    props: {
		cartList: {
			type: Array,
			default:function(){
				return [];
			}
		}
	},
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章