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

vue vue3 手写 动态加载组件

效果展示

一、需求背景:

# vue3 项目涉及很多图表加载、表格加载 #考虑手写一个动态加载组件

二、实现思路

通过一个加载状态变量,通过v-if判断,加载状态的变量等于哪一个,动态加载组件内部就显示的哪一块组件。

三、实现效果

四、代码

(一)、封装组件

<template><view class="loadding_contaniers" v-if="loadState == 1"><view class="loading_img"><image src="@/static/images/smartCabin/loadingImg/isLoading_bg.png" /></view><view class="imgTitle">加载中<text id="dot">...</text></view></view><view class="loadding_contaniers" v-else-if="loadState == 2"><view class="loading_img"><image src="@/static/images/smartCabin/loadingImg/isErr_bg.png" /></view><view class="imgTitle">请求失败,请重新加载!</view></view><view class="loadding_contaniers" v-else-if="loadState == 3"><view class="loading_img"><image src="@/static/images/smartCabin/loadingImg/isNone_bg.png" /><!-- <image:src="getAssetsFile(props.noticeTip == '暂无数据'? `smartCabin/loadingImg/isNone_bg.png`: `smartCabin/loadingImg/isErr_bg2.png`)"/> --></view><view class="imgTitle">{{ noticeTip }}</view></view><view class="loadding_sucess" v-else><slot> </slot></view>
</template><script>
export default {props: {// 1:加载中 2:加载失败 3:暂无数据 4:加载成功loadState: Number,noticeTip: {type: String,default: "暂无数据",},},
};
</script><style lang="scss">
.loadding_contaniers {width: 100%;height: 100%;display: flex;flex-direction: column;align-items: center;justify-content: center;.loading_img {image {width: 260rpx;height: 260rpx;}}.imgTitle {flex: 1;height: 0;color: #757575;#dot {display: inline-block;width: 1.5em;vertical-align: bottom;overflow: hidden;animation: dotting 0.5s infinite step-start;}@keyframes dotting {0% {width: 0;margin-right: 1.5em;}33% {width: 0.5em;margin-right: 1em;}66% {width: 1em;margin-right: 0.5em;}100% {width: 1.5em;margin-right: 0;}}}
}
.loadding_sucess {width: 100%;height: 100%;display: flex;justify-content: center;align-items: center;
}
</style>

 (二)、组件传参

h5使用

<LoaddING :loadState="4" :noticeTip="'当loadState是成功的时候'"><view class="myContent"><imagesrc="@/static/images/energy/elePower/receiving_power.png"/></view>
</LoaddING>

web端使用 

<LoaddING :loadState="data.isFinish" :noticeTip="data.isTips"><!-- 插槽组件 --><ewClickLine:yAxisUnit="echartData2.unit":seriesColor="echartData2.color":legend="{ show: true, x: '80%' }":seriesName="echartData2.name":seriesType="echartData2.chartSeriesType":xAxisValue="echartData2.lineXAxisValue":nums="echartData2.lineNums"></ewClickLine>
</LoaddING>

http://www.lryc.cn/news/335850.html

相关文章:

  • HTML:表单
  • 即插即用篇 | YOLOv5/v7引入Haar小波下采样 | 一种简单而有效的语义分割下采样模块
  • Plonky2.5:在Plonky2中验证Plonky3 proof
  • 卷积通用模型的剪枝、蒸馏---剪枝篇(此处以deeplabv3+为例,可根据模型自行定制剪枝层)
  • 使用Ollama在本地运行AI大模型gemma
  • 【IC前端虚拟项目】时序面积优化与综合代码出版本交付
  • windows版本-idea中下载的java版本在哪
  • 设计模式:创建者模式
  • 【linux】基础IO(四)
  • 集合框架(数组,Arrays.sort,list,map,set,stack,queue)蓝桥杯习题
  • 【C++基础】运算符和流程控制语句
  • AOF文件重写
  • 第四次面试总结 — 嘉和智能 - 全栈开发
  • tx-lcn使用
  • oracle恢复异常处理
  • 谈谈什么是 Redis
  • 备战蓝桥杯(java)(日益更新)
  • 06 Php学习:字符串
  • python画图Matplotlib和Seaborn
  • 一体式I/O模块与RS485串口联动,实现工业网络无缝对接
  • 如何在Uniapp真机中使用H.265无插件流媒体播放器EasyPlayer
  • 【MySQL数据库 | 第二十五篇】深入探讨MVCC底层原理
  • 【LAMMPS学习】八、基础知识(1.6) LAMMPS 与其他代码耦合
  • ArrayList中多线程的不安全问题
  • ALTER TABLE 之 定点变更(in-place alter)
  • 【RAG实践】Rerank,让大模型 RAG 更近一步
  • 私有化客服系统:在线客服搭建与部署的创新之路
  • VM-UNet: Vision Mamba UNet for Medical Image Segmentation
  • 面向对象编程:在Python中的面向对象编程奥秘
  • 考研数学|零基础100分保底复习方案+资料分享