关于@vue-office/excel 渲染异常滚动失去内容

关于@vue-office/excel 渲染异常滚动失去内容

javascript 复制代码
<template>
  <div class="w-full h-full min-h-[500px] relative bg-white">
    <div v-if="loading" class="absolute inset-0 flex items-center justify-center">
      <div class="flex flex-col items-center gap-3">
        <svg class="animate-spin h-8 w-8 text-[#f86c31]" viewBox="0 0 24 24">
          <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none" />
          <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
        </svg>
        <span class="text-sm text-gray-500">加载中...</span>
      </div>
    </div>
    <div v-if="error" class="absolute inset-0 flex items-center justify-center">
      <div class="flex flex-col items-center gap-3 text-center">
        <div class="w-12 h-12 rounded-full bg-red-50 flex items-center justify-center">
          <svg class="w-6 h-6 text-red-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
          </svg>
        </div>
        <p class="text-sm text-gray-600">{{ error }}</p>
      </div>
    </div>
    <Excel
      v-show="!error"
      :src="src"
      @rendered="handleRendered"
      @error="handleError"
    />
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import Excel from "@vue-office/excel";
import "@vue-office/excel/lib/v3/index.css";

const props = defineProps<{
  src: string;
}>();

const loading = ref(true);
const error = ref<string | null>(null);

function handleRendered() {
  loading.value = false;
}

function handleError(err: unknown) {
  loading.value = false;
  error.value = "Excel 表格加载失败,请检查文件是否存在或格式是否正确";
  console.error("Excel render error:", err);
}
</script>

<style scoped>


</style>

只需要加上Excel对应的样式即可 import "@vue-office/excel/lib/v3/index.css";

相关推荐
kyriewen4 分钟前
别再用防抖做懒加载了:120 张图只加载出 4 张
前端·javascript·程序员
计算机魔术师10 分钟前
Hugging Face CEO 转评前 DOGE 研究人员用 AI 智能体渗透 Anthropic 系统事件
前端
IT_陈寒18 分钟前
刚解决一个 Java 并发问题,这坑踩得我怀疑人生
前端·人工智能·后端
前端一课18 分钟前
一个晚上,四个“小问题”:我重写了 12 章 ArkUI 笔记
前端
小码哥_常30 分钟前
前端图片压缩实战——我把网站图片体积砍了 70%
前端
张一凡9344 分钟前
把“不要乱改”从提示词里拿出来,放进可校验的提案里
前端·后端·架构
木子欢儿1 小时前
Debian 13 + vsftpd 搭建FTP服务
linux·服务器·前端·网络·debian
leeguoo1 小时前
让 Claude Code / Codex 用上你已登录的 Chrome
前端·chrome·ai编程
天蒙蒙亮1 小时前
打安卓apk包+“应用商城”发布
前端·uni-app
Lank_M1 小时前
视频压到指定大小总超一截?码率控制的误差拆开看
前端