关于@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";

相关推荐
PedroQue9910 小时前
0.5.0重磅发布:动画插件+H5体验全面优化
前端·uni-app
金虹桥程序员10 小时前
【动画】 📚 CSS 动画与 GPU 合成层优化全链路指南
前端·面试
程序员老赵10 小时前
Docker 部署填鸭表单完整教程:搭建私有化问卷与表单收集平台
前端·docker·开源
无限压榨切图仔10 小时前
向量库能搜到内容,为什么还不算学会 RAG
前端·agent
mmsx10 小时前
MapLibre 实战 11|用户说"我的地块丢了":一个 sealed class 图层模型,和四个让我重构三版的坑
android·前端·开源
xqchen10 小时前
代码差异可视化方案选型:diff2html 实战指南
前端
名字还没想好☜10 小时前
用 Zustand 做 React 全局状态管理:告别 Context 重渲染,3 个实战模式与持久化
前端
IMPYLH11 小时前
HTML 的 <section> 元素
前端·html
X1A0RAN11 小时前
密匣 PsdKeep:一个属于你自己的 Chrome 账号记事本
前端·chrome
529宝宝起名网11 小时前
用 Python 开发历史名字查询与起名灵感工具:从古籍人物数据库到名字文化故事生成
开发语言·前端·python