最初想使用watch
配合着 computed
来监听父组件数据,发现没有必要反而造成代码冗余,如果参数一多很难维护。
正确方式:直接使用computed监听就好
// 子组件
<script>
export default {props: {yesterDayfollow: {type: Array},transpond: {type: Array},cumulateUsers: {type: Array}},setup(props) {let yesterDayfollowRef = computed(() => props.yesterDayfollow.length) // 昨日关注let transpondRef = computed(() => props.transpond.length) // 昨日分享let cumulateUserRef = computed(() => props.cumulateUsers[0] && props.cumulateUsers[0].cumulate_user) // 总用户数据return {yesterDayfollowRef,transpondRef,cumulateUserRef}}
}
</script>}
// 获取昨日新增关注人数
getUserSummary(yesterDay, yesterDay).then((r) => {yesterDayfollow.value = r.list
})// 获取图文分享转发数据
getUserShare(yesterDay, yesterDay).then((r) => {transpondRef.value = r.list
})// 获取累计总用户数
getUserCumulate(yesterDay, yesterDay).then((r) => {cumulateUsers.value = r.list
})