get_houdai.js
export default function get_houdai(node) {
let total_houdai = 1 // 默认值1 是它自己
for (const houdai of node.$children)
total_houdai += get_houdai(houdai)
return total_houdai
}
main.js
import get_houdai from '@/get_houdai'
Vue.prototype.$get_houdai = get_houdai
组件(点击显示后代个数)
<template>
<div id="zxcv" @click.self="show_subs">
</div>
</template>
<script>
export default {
methods: {
show_subs() {
console.log(this.$get_houdai(this))
},
},
}
</script>
<style lang="less">
#zxcv {
width: 100px;
height: 100px;
background-color: coral;
}
</style>
网友评论