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

相关推荐
kyriewen8 小时前
编辑弹窗点了取消,列表里的数据怎么还是变了?
前端·javascript·人工智能
Karl_fang8 小时前
🥳 再也不用拿起手机抄验证码!我做了一个 Android → Mac 的「验证码接力」工具
前端·macos·ai编程
谭光志9 小时前
如何让 AI 高效工作
前端·后端·ai编程
FRing0310 小时前
vue2干货总结11(短信验证、登录功能、统一处理错误(响应拦截器)、将token信息存入vuex、vuex持久化处理)
开发语言·前端·javascript·vue.js·vue2
泯泷10 小时前
改一个字,整段都红了?——中文内容差异对比的算法与协议设计
前端·javascript·typescript
再吃一根胡萝卜10 小时前
DSH plugin 开发示例:五种插件形态完整代码整理
前端
Yk酱2284011 小时前
A2UI随笔-demo-01
前端
云起SAAS11 小时前
本地生活同城多商户商城系统源码源码 合伙人分红加区域代理加排队返现
前端·javascript·后端
奶油话梅糖11 小时前
3 天 1,705 Star:DeepSeek 开源官方聊天前端——零后端纯静态,浏览器直连 API
前端·开源
Linye11 小时前
HTML 流程图连线交叉看不清?聊聊画布避障折线与跳弧实现
前端·人工智能