uniapp+<script setup lang=“ts“>解决有数据与暂无数据切换显示,有数据加载时暂无数据闪现(先加载空数据)问题

声明showEmpty 为false,在接口返回处判断有数据时设置showEmpty 为false,接口返回数据为空则判断showEmpty 为true (这样就解决有数据的时候会闪现暂无数据的问题啦)

复制代码
<!--
 * @Date: 2024-02-26 03:38:52
 * @LastEditTime: 2025-06-05 09:02:58
 * @Description: 救援详情页面
-->
<template>
    <view class="consolidated-order">
        <view class="consolidated-order-filter">
            <view class="consolidated-order-filter-cont flex-center-between">
                <select-date ref="dateRef" @change-date="changeDate" />
                <select-time ref="timeRef" @change-time="changeTime" />
                <select-goods ref="goodsRef" @change-goods="changeGoods" />
            </view>
        </view>
        <scroll-view
            v-if="!showEmpty"
            scroll-with-animation
            :scroll-y="true"
            :show-scrollbar="false"
            class="consolidated-cont"
        >
            <view class="service-order-item-box">
                <view v-for="(item, index) in splicingOrdersList" :key="index" class="service-order-item">
                    <view class="service-order-item-time"
                        >{{ timeFormat(item.departureTime) }} - {{ timeFormat(item.arriveTime) }}</view
                    >
                    <view
                        v-for="(item1, index1) in item.flyRecordModelList"
                        :key="index1"
                        class="service-order-item-cont flex-center-start"
                    >
                        <view class="cont-left flex-center-between">
                            <view class="fly-no-box fly-no-yellow flex-center-start">
                                <view class="fly-no-text">架次</view
                                ><view class="fly-no-num">{{ item1.flyNo || '--' }}</view></view
                            >
                            <view class="fly-id">飞行记录ID:{{ item1.id }}</view>
                        </view>
                        <view class="cont-right flex-center-start">
                            <view class="balance-num">空位:{{ item1.balanceNum }}人</view>
                            <view class="service-order-item-btn" @click="splicingOrders(item1)">拼单</view>
                        </view>
                    </view>
                </view>
            </view>
        </scroll-view>
        <!-- 拼单空状态 -->
        <view v-if="showEmpty" class="empty-wrap">
            <empty-block :image-src="EMPTY_PNG" text="还没有拼单信息哦" />
        </view>
    </view>
</template>

<script setup lang="ts">
import config from '@/../config/config';
import { qryCanJoinFly, combineServerOrder } from '@/services/api-order';
import { timeFormat } from '@/utils/DateUtils';
import { onLoad } from '@dcloudio/uni-app';
import { computed, ref, onMounted } from 'vue';
const EMPTY_PNG = `${config.assetPath}/images/book/empty-order.png`;
import { useStore } from 'vuex';
const store = useStore();
const openId = computed(() => store.state.userStore?.userInfo.openId);
const changeDate = (e) => {};
const changeTime = (e) => {};
const changeGoods = (e) => {};
const splicingOrdersList = ref();
const orderNoVal = ref();
const showEmpty = ref(false); //是否显示空状态
// 拼单列表
const getCanJoinFly = async () => {
    // ATO24080900075466有数据
    await qryCanJoinFly({
        orderNo: orderNoVal.value,
    }).then((res) => {
        if (res?.code == 0 && res?.data) {
           if (res?.data.length <= 0) {
                showEmpty.value = true; //没有数据的时候展示空状态
            } else {
                showEmpty.value = false; //有数据则正常展示数据
            }
            splicingOrdersList.value = res?.data;
        }
    });
};
const splicingOrders = (item) => {
    uni.showModal({
        title: '',
        content: '是否选择拼机',
        confirmText: '确认',
        success: (data) => {
            if (data.confirm) {
                let params = {
                    orderNo: orderNoVal.value,
                    combineFlyId: item.id,
                    openId: openId.value,
                };
                combineServerOrder(params).then((res) => {
                    if (res?.code == 0) {
                        uni.showToast({
                            title: '拼机成功',
                            icon: 'success',
                        });
                    }
                });
            } else if (data.cancel) {
                console.log('用户取消了操作');
            }
        },
    });
};
onLoad((option) => {
    orderNoVal.value = option.orderNo || '';
});
onMounted(() => {
    getCanJoinFly();
});
</script>

<style lang="scss">
@import './index.scss';
</style>

有数据

空状态

相关推荐
anyup20 小时前
【全端支持】 uni-app x 专用请求库:axios 写法,多实例、拦截器、可中断、上传下载
前端·uni-app·unix
anyup2 天前
uView Pro X 2.0 发布:弃用 UTS,全面支持 TypeScript 的 uni-app x 蒸汽模式 UI 框架
前端·uni-app·ai编程
wuxianda10306 天前
uniapp 与跨端打包项目:壳子和框架层默认特征,相似是从哪里来的
uni-app
码间留白6 天前
uni-app 鸿蒙端提现点不动?我用 UTS 插件补上了微信"确认收款"
uni-app·harmonyos·鸿蒙·uts插件·微信商家转账
wuxianda10306 天前
苹果 App 上架 4.3(a) 问题解决方案(适用 uniapp、Objective-C、Swift、Flutter 等项目)
uni-app·objective-c·swift
码间留白8 天前
AI 给的两个方案都被我否了:把 startIcon 与启动遮罩做成同一张图,鸿蒙 APP 冷启动零白屏
性能优化·uni-app·ai编程·harmonyos
anyup8 天前
自带 uni-app x 页面级能力,uView Pro X 8 个开箱即用的工具函数
前端·vue.js·uni-app
码间留白13 天前
六轮真机实验后,我把鸿蒙直播推流的 UI 全逼成了原生——uni-app 适配 HarmonyOS NEXT 完整复盘
uni-app·鸿蒙·harmonyos next·直播推流·arkts/arkui
wuxianda103015 天前
2026 苹果审核 4.3 (a) 被拒全解析|Guideline 4.3a spam 马甲包拒审原因 + 避坑方案
flutter·uni-app·苹果上架
头发还在的女程序员16 天前
基于 Spring Boot + Vue 3 + uni-app 的灵活用工系统:四端架构与业务流程设计
vue.js·spring boot·uni-app·灵活用工·灵工系统