Vue中props
props配置項(xiàng)
功能:讓組件接收外部傳過(guò)來(lái)的數(shù)據(jù)
傳遞數(shù)據(jù):<Demo name="xxxx" />
接收數(shù)據(jù):
1、只接收: props : [ 'name' ]
2、限制類型:props : { name : String }
3、限制類型、限制必要性、指定默認(rèn)值
props : { name : { type : String, // 類型 required : true, // 必要性 default : '老王' // 默認(rèn)值 } }
備注:
props是只讀的,Vue底層會(huì)監(jiān)測(cè)對(duì)props的修改,如果進(jìn)行了修改,就會(huì)發(fā)出警告,若業(yè)務(wù)需求確實(shí)需要修改,那么請(qǐng)復(fù)制props的內(nèi)容到data中一份,然后去修改data中的數(shù)據(jù)
props適用于:
(1)父組件 ===> 子組件 通訊
(2)子組件 ===> 父組件 通訊(要求父先給子一個(gè)函數(shù))
業(yè)務(wù)需求變更永無(wú)休止,技術(shù)前進(jìn)就永無(wú)止境!

浙公網(wǎng)安備 33010602011771號(hào)