vue3获取对象长度(非数组长度)
对象结构
App.vue
<template>
<footers :data="data" />
</template>
<script>
export default {
data() {
return {
data: {
me: {
paritcles: {
title: '文章',
icon: '../../public/meView/paritcle.svg',
data: [],
author: '林林'// 作者
},
gropus: {
title: '分组',
icon: '../../public/meView/group.svg',
data: [],
author: '林林'// 作者
},
collections: {
title: '收藏',
icon: '../../public/meView/collections.svg',
data: [],
author: '林林'// 作者
},
shing: {
title: '审核中',
icon: '../../public/meView/shing.svg',
data: [],
author: '林林'// 作者
}
}
}
}
},
}
</script>
MeView.vue
export default {
setup(props, { attrs }) {
// 传递的数据
const data = ref(attrs.data.me)
const dataLen = Object.keys(data.value).length;
console.log(Object.keys(data.value))
console.log(dataLen)
}
}