Vue組件是天然支持遞回使用的,只需要在參考自己時使用跟該組件name相同的tag就行了,比如:
<template>
<div>
{{ item.name }}
<template v-if="item.children">
<tree-node v-for="child of item.children" :item="child"/>
</template>
<div>
</template>
<script>
export default {
name: 'TreeNode',
......
};
</script>
那么如果到這里就結束了就沒意思了,我要說的是為什么Vue組件能支持遞回使用呢,只要從原始碼級別上來分析,我這里用的原始碼的版本是2.5.21
我們定位到src\core\global-api\extend.js這個檔案,在其中有這樣一段代碼

就是把組件自己又注冊到了組件的components里了,就是這樣
如果你覺得有幫助,請幫忙點贊哦:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/171625.html
標籤:其他
上一篇:滲透測驗面試問題合集
下一篇:DFS(思路加簡單例題)
