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. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條2. Ajax對(duì)xml信息的接收和處理操作實(shí)例分析3. Jsp中request的3個(gè)基礎(chǔ)實(shí)踐4. Ajax返回值類型與用法實(shí)例分析5. Java實(shí)戰(zhàn)之實(shí)現(xiàn)一個(gè)好用的MybatisPlus代碼生成器6. python簡(jiǎn)單實(shí)現(xiàn)9宮格圖片實(shí)例7. php根據(jù)id生成10位不重復(fù)數(shù)字跟字母混合字符串8. ASP動(dòng)態(tài)include文件9. php設(shè)計(jì)模式之迭代器模式實(shí)例分析【星際爭(zhēng)霸游戲案例】10. Python request中文亂碼問(wèn)題解決方案
