vue props default Array或是Object的正確寫(xiě)法說(shuō)明
1、錯(cuò)誤寫(xiě)法
demo:{ type:Array, default:[]}
eslint語(yǔ)法報(bào)錯(cuò):
Invalid default value for prop “demo”: Props with type Object/Array must use a factory function to return the default value.
2、正確的寫(xiě)法應(yīng)該是:
demo: { type: Array, default: function () { return [] }}
或是用箭頭函數(shù):
demo: { type: Array, default: () => []}
3、對(duì)象的箭頭函數(shù)寫(xiě)法:
demoObj: { type: Object, default: () => ({})}
或是常規(guī)
demoObj: {type: Object,default: function () {return {}}}
錯(cuò)誤的寫(xiě)法
demoObj: () => {}
補(bǔ)充知識(shí):vue 傳參props里面為什么要帶type,還有default?
這個(gè)是子組件啦 ,寫(xiě)type的意思是swiperDate傳過(guò)來(lái)的數(shù)據(jù)類型是數(shù)組,default就是表示不傳默認(rèn)返回的[ ],空數(shù)組.
這種就是表示傳的數(shù)據(jù)類型是number,不傳默認(rèn)是0。
以上這篇vue props default Array或是Object的正確寫(xiě)法說(shuō)明就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于PHP做個(gè)圖片防盜鏈2. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁(yè)3. XML在語(yǔ)音合成中的應(yīng)用4. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解5. .NET中實(shí)現(xiàn)對(duì)象數(shù)據(jù)映射示例詳解6. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)7. ASP.NET MVC把數(shù)據(jù)庫(kù)中枚舉項(xiàng)的數(shù)字轉(zhuǎn)換成文字8. 如何使用ASP.NET Core 配置文件9. jscript與vbscript 操作XML元素屬性的代碼10. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車輛管理系統(tǒng)
