记录一下美妙的父传子时间:
- 父组件
const total = ref(0);
const getTotal = (value: number) => {
total.value = value;
console.log('子传父的总订单数:' + total.value);
};
<view class="h-42rpx"> <text class="text-26rpx leading-24rpx h-42rpx text-#222 mt-5rpx whitespace-nowrap"> {{ total }}个订单 </text> </view> <orderPanel ref="listItem" :tabIndex="index" :currentIndex="current" :startTime="startTime" :endTime="endTime" :getTotal="getTotal" :status="status" />
- 子组件
const props = defineProps(['tabIndex', 'currentIndex', 'startTime', 'endTime', 'status', 'getTotal']);
props.getTotal(res.data[0].total.num);
另外送一个:
watch( () => props.status, () => { if (props.currentIndex === props.tabIndex) { paging.value.reload(); } }, );