当前位置: 首页 > news >正文

Ant ASpin自定义 indicator 报错

目录

一、问题

二、原因及解决方法

三、总结


一、问题

1.太多地方用到 Aspin了,还要使用h来自己,写style渲染。想着封装一下传值就可以。

2.没想到还搞出问题:线下报错,线上不报错。

3.报错具体如下:

chunk-QEPXSSG5.js?v=da510c8d:7137 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'type')at unmountComponent (chunk-QEPXSSG5.js?v=da510c8d:7137:18)at unmount (chunk-QEPXSSG5.js?v=da510c8d:7048:7)at unmountChildren (chunk-QEPXSSG5.js?v=da510c8d:7167:7)at unmount (chunk-QEPXSSG5.js?v=da510c8d:7068:9)at unmountComponent (chunk-QEPXSSG5.js?v=da510c8d:7147:7)at unmount (chunk-QEPXSSG5.js?v=da510c8d:7048:7)at unmountChildren (chunk-QEPXSSG5.js?v=da510c8d:7167:7)at unmount (chunk-QEPXSSG5.js?v=da510c8d:7076:9)at unmountChildren (chunk-QEPXSSG5.js?v=da510c8d:7167:7)at unmount (chunk-QEPXSSG5.js?v=da510c8d:7076:9)
Promise.then		
callAsyncFunc	@	useAsyncLoading.ts:17
await in callAsyncFunc		
handleCheck	@	OnlineInvoice.vue:256

4.报错的地方是 loading.value=false这行代码,大致意思是组件没有正常卸载。但是我也没有写啥呀。就很常见的逻辑:调接口前loading,调完接口后取消loading而已。

5.具体代码如下:

6.我推测的错误原因:

        1)Asteps异步,还没有加载完。但是吧,Asteps完全就是一个样式,和逻辑没有啥关系

        2)handleNext影响逻辑,去除,也没有用

        3)DeepSeek问了一下,它说可能是CommonDrawer控制显示的isShowModal没有正确执行。试了一直显示也没有用

        4)真是奇了怪呀,我啥也没写呀,看着没有问题呀。

二、原因及解决方法

1.问了一下大佬,然后说CommonLoading有问题,我也是蒙圈了。设想了十几种可能性,都是在错误的道路上无效努力。

2.具体代码如下:乍一看,好像没有毛病呀。但是吧,把他注释了还真不报错了。

<template><!-- 加载中 --><ASpin :indicator="indicator"></ASpin>
</template>
<script lang="ts" setup>
import { Loading3QuartersOutlined } from '@ant-design/icons-vue'const props = withDefaults(defineProps<{ fontSize?: number; svg?: any; color?: string; fontWeight?: string }>(), {fontSize: 12,color: '#B3B3B3',fontWeight: 'bold'
})const indicator = computed(() => {const icon = props.svg ?? Loading3QuartersOutlinedreturn h(icon, {style: {fontSize: `${props.fontSize}px`,fontWeight: props.fontWeight,color: props.color},spin: true})
})
</script>

3.搞不懂,commonLoading是基于ASpin写的,去看看官网怎么写的,结果去官网看了。总结就是直接赋值

4.那我不用computed直接赋值是不是也可以呢?试了一下,还真可以

<template><!-- 加载中 --><ASpin :indicator="indicator"></ASpin>
</template>
<script lang="ts" setup>
import { Loading3QuartersOutlined } from '@ant-design/icons-vue'
const props = withDefaults(defineProps<{ fontSize?: number; svg?: any; color?: string; fontWeight?: string }>(), {fontSize: 12,color: '#B3B3B3',fontWeight: 'bold'
})const indicator = ref()
function initIndicator() {const icon = props.svg ?? Loading3QuartersOutlinedindicator.value = h(icon, {style: {fontSize: `${props.fontSize}px`,fontWeight: props.fontWeight,color: props.color},spin: true})
}
initIndicator()
</script>

5. 但是我真的不了解呀,为啥用 computed就无法正常卸载。DeepSeek还让我自己写动画来着,然后并没有用。用computed必定会报错@~~@,看不懂

三、总结

1. 遇到报错 组件没有正常卸载 unmountComponent,Cannot read properties of null (reading 'insertBefore')时,定位到具体的代码,要着重看 报错行包裹的代码!!!

不要像我一样,疏忽大意,只想着外面的代码有问题🤣

2.现确认自己的逻辑是否有问题

3.如果确认自己的逻辑没有问题。需要着重注意 二次封装的第三方组件有没有问题。尝试注释排除法找到具体的错误位置,再到官网找到具体的例子照着写

4.不过我是真搞不懂为啥 computed会导致Aspin组件无法正常卸载。有大佬知道,欢迎评论,谢谢!

/*

希望对你有帮助!

如有错误,欢迎指正!

*/

http://www.xdnf.cn/news/1102195.html

相关文章:

  • 模拟开关、可编程增益仪表放大器电路
  • VLM-R1 + GRPO 算法完整复现全过程日志
  • 随手记录第二十话 -- Python3版本虚拟环境安装与AI的接入使用
  • RuoYi+Uniapp(uni-ui)开发商城系统
  • python学习DataFrame数据结构
  • 数据结构第一章复杂度的认识
  • 【java17】使用 Word 模板导出带替换符、动态表格和二维码的文档
  • iOS 数组如何设计线程安全
  • 提示工程:突破Transformer极限的计算科学
  • 工具分享--IP与域名提取工具
  • Spring 声明式事务:从原理到实现的完整解析
  • 小架构step系列11:单元测试引入
  • 分享|2025年机器学习工程师职业技术证书报考指南
  • 如何使用 Python 删除 Excel 中的行、列和单元格 – 详解
  • 《探索电脑麦克风声音采集多窗口实时可视化技术》
  • xFile:高性能虚拟分布式加密存储系统——Go
  • 上位机知识篇---Git符号链接
  • python的类型注解讲解
  • 云、实时、时序数据库混合应用:医疗数据管理的革新与展望(中)
  • 电力自动化的通信中枢,为何工业交换机越来越重要?
  • NLP_知识图谱_大模型——个人学习记录
  • CentOS 安装 JDK+ NGINX+ Tomcat + Redis + MySQL搭建项目环境
  • LVS-NAT模式配置
  • Java语言基础
  • Windos服务器升级MySQL版本
  • 从Excel到PDF一步到位的台签打印解决方案
  • 5G标准学习笔记14 - CSI--RS概述
  • 《磁力下载工具实测:资源搜索+高速下载一站式解决方案》
  • P1204 [USACO1.2] 挤牛奶Milking Cows
  • 【Linux】GDB/CGDB 调试器学习笔记