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

【Vue】word / excel / ppt / pdf / 视频(mp4,mov) 预览

文件预览

    • Vue3
    • 一. word
    • 二. excel
    • 三. ppt
    • 四. pdf
      • 4.1 vue-pdf-embed
      • 4.2 iframe
    • 五. 视频
    • 六:扩展——kkFileView

Vue3

一. word

  1. 安装:npm install docx-preview
  2. 父页面
<template><div><DocPreviewv-if="filePath.includes('docx')":doc-url="filePath"/></div>
</template>
<script setup>
import DocPreview from '@/components/DocPreview'
const filePath = ref('https://xxxxxxxxxxxx.docx') 
</script>
  1. 组件
    路径:@/components/DocPreview
<!-- word 文档阅读 -->
<template><div><div v-if="message" class="doc-empty">{{ message }}</div><div v-else class="doc-render-wraper"><div ref="fileRef"><div ref="fileStyleRef"></div></div></div></div>
</template><script setup>
import axios from 'axios'
// const docx = require('docx-preview')
import { renderAsync } from 'docx-preview'const props = defineProps({// 文档地址docUrl: {type: String,default: ''}
})const service = axios.create({baseURL: props.docUrl,timeout: 600000
})
const fileRef = ref(null)
const fileStyleRef = ref(null)
const message = ref('')
// 预览
const init = async () => {const { data } = await service({method: 'get',responseType: 'blob'})// console.log(data)if (data.size === 0) {message.value = '当前文档内容为空,无可阅读内容'} else {message.value = ''renderAsync(data, fileRef.value, fileStyleRef.value)}
}watch(() => props.docUrl,newVal => {if (newVal !== null && newVal !== '') {init()}}
)init()
</script>
<style lang="scss" scoped>
.doc-render-wraper {width: 840px;padding-top: 10px;margin: 0 auto;overflow-x: auto;// fileStyleRef css> div {border: 1px solid #e6edf5;}
}
.doc-empty {display: flex;align-items: center;justify-content: center;font-size: 14px;color: #0f5c9f;background-color: #e6edf5;width: 100%;height: 50px;
}
</style>

二. excel

在这里插入图片描述

  1. 安装:npm install @vue-office/excel
  2. 父页面
<template><div><XlsxPreview :xlsx-url="filePath" /></div>
</template>
<script setup>
import XlsxPreview from '@/components/XlsxPreview'
</script>
  1. 组件
<!-- excel 文档阅读 -->
<template><div class="xlsx-preview"><vue-office-excel :src="source" class="vue-office-excel" /></div>
</template>
<script setup>
// 引入VueOfficeExcel组件
import VueOfficeExcel from '@vue-office/excel'
// 引入相关样式
import '@vue-office/excel/lib/index.css'
const props = defineProps({// 文档地址xlsxUrl: {type: String,default: ''}
})
const source = ref(props.xlsxUrl)
</script>
<style lang="scss" scoped>
.xlsx-preview {width: 840px;height: 100%;padding: 20px 0;margin: 0 auto;box-sizing: border-box;
}
.vue-office-excel {width: 100%;height: 100%;border: 1px solid #e5e5e5;margin: 0 auto;box-sizing: border-box;
}
</style>

三. ppt

  1. 官网:https://github.com/meshesha/PPTXjs
    demo:https://pptx.js.org/pages/demos.html
  2. 注意:先引入pptjs
    在这里插入图片描述
    在这里插入图片描述
  3. 父文件
<template><div><PptxPreview :pptx-url="filePath" /></div>
</template>
<script setup>
import PptxPreview from '@/components/PptxPreview/index.vue'
const filePath = ref("")</script>
  1. 组件
<!-- pptx 文档阅读 -->
<template><div class="xlsx-preview"><div class="page-tool"><div class="page-tool-item" @click="pageZoomOut">放大</div><div class="page-tool-item" @click="pageZoomIn">缩小</div></div><!-- <div style="display: grid; place-content: center; color: darkgrey">pptx文件暂时无法预览~~~</div> --><div style="height: 1200px; width: 90%; zoom: 0.5; overflow-y: auto; overflow-x: auto; margin: 0 30px"><divid="your_div_id_result"style="position: relative":style="`transform:scale(${size});transform-origin:0% 0%`"></div></div></div>
</template>
<script setup>
const props = defineProps({// 文档地址pptxUrl: {type: String,default: ''}
})
const size = ref(1)
function init(newVal) {$('#your_div_id_result').pptxToHtml({pptxFileUrl: newVal,slidesScale: '50%'})
}
onBeforeUnmount(() => {$('#your_div_id_result').empty()
})
const pageZoomOut = () => {if (size.value < 3) {size.value += 0.1}
}
const pageZoomIn = () => {if (size.value > 0.8) {size.value -= 0.1}
}
watch(() => props.pptxUrl,newVal => {if (newVal) {setTimeout(() => {init(newVal)}, 1000)}},{ immediate: true }
)
</script>
<style lang="scss" scoped>
// import './css/pptxjs.css' import './css/nv.d3.min.css'
.xlsx-preview {width: 840px;height: 100%;// margin-left: 80px;padding: 20px 0;// margin: 0 auto;box-sizing: border-box;
}
.vue-office-excel {width: 100%;height: 100%;border: 1px solid #e5e5e5;margin: 0 auto;box-sizing: border-box;
}.page-tool {display: flex;align-items: center;justify-content: center;margin-left: 50px;margin-bottom: 20px;padding: 8px 0;// width: 400px;width: 80%;text-align: center;background: #e6edf5;color: #0f5c9f;border-radius: 19px;cursor: pointer;
}.page-tool-item {padding: 0 15px;padding-left: 10px;cursor: pointer;
}
</style>
  1. 缺陷
    (1)不支持上传jpg格式的图片:若ppt中含有jpg格式的图片,报错
    (2)支持仅pptx文件格式

四. pdf

4.1 vue-pdf-embed

功能:放大、缩小、跳转到某页
在这里插入图片描述

  1. 安装: npm install vue-pdf-embed
  2. 父页面
<template><div><PdfPreview :key="fileIndex" :pdf-url="filePath" /></div>
<template>
<script setup>
const fileIndex = ref(0)
const filePath = ref(https://xxxxxxxxxxxxxxx.pdf)</script>
  1. 组件
<template><div class="pdf-preview"><div v-if="props.pdfUrl.indexOf('undefined') == -1" v-loading="pdfLoading"><div class="page-tool"><div class="page-tool-item" @click="lastPage">上一页</div><div class="page-tool-item" @click="nextPage">下一页</div><div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div><div class="page-tool-item" @click="pageZoomOut">放大</div><div class="page-tool-item" @click="pageZoomIn">缩小</div><div class="page-tool-item">前往</div><el-input v-model.number="currentPage" style="width: 100px" @input="goToPage(currentPage)" /></div><div class="pdf-wrap"><vue-pdf-embedref="pdfRef":source="{cMapUrl: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.6.347/cmaps/',url: state.source,cMapPacked: true}"class="vue-pdf-embed":style="`transform:scale(${state.scale});transform-origin:0% 0%`":page="state.pageNum"@loading-failed="pdfLoading = false"@rendered="handleDocumentRender"/></div></div></div>
</template>
<script setup>
import { defineAsyncComponent } from 'vue'
const { proxy } = getCurrentInstance()
const VuePdfEmbed = defineAsyncComponent(() => import('vue-pdf-embed'))
const props = defineProps({pdfUrl: {type: String,required: true,default: ''}
})
const pdfLoading = ref(true)
const currentPage = ref(1)
const state = reactive({source: props.pdfUrl, // 预览pdf文件地址pageNum: 1, // 当前页面scale: 1, // 缩放比例numPages: 0 // 总页数
})// 加载完成
const handleDocumentRender = () => {pdfLoading.value = falsestate.numPages = proxy.$refs.pdfRef.pageCount
}
const lastPage = () => {if (state.pageNum > 1) {state.pageNum -= 1currentPage.value = state.pageNum}
}const nextPage = () => {if (state.pageNum < state.numPages) {state.pageNum += 1currentPage.value = state.pageNum}
}
const pageZoomOut = () => {if (state.scale < 3) {state.scale += 0.1}
}
const pageZoomIn = () => {if (state.scale > 0.8) {state.scale -= 0.1}
}const goToPage = page => {if (page >= 1 && page <= state.numPages) {currentPage.value = pagestate.pageNum = page}
}
</script>
<style lang="scss" scoped>
.pdf-preview {//   position: relative;width: 840px;// height: 1250px;padding: 10px 0;margin: 0 auto;box-sizing: border-box;
}
.pdf-wrap {overflow-y: auto;
}
.vue-pdf-embed {text-align: center;width: 100%;border: 1px solid #e5e5e5;margin: 0 auto;box-sizing: border-box;
}.page-tool {display: flex;align-items: center;justify-content: center;margin: 10px auto;// width: 400px;width: 80%;text-align: center;background: #e6edf5;color: #0f5c9f;border-radius: 19px;cursor: pointer;
}.page-tool-item {padding: 0 15px;padding-left: 10px;cursor: pointer;
}
</style>

4.2 iframe

<template><div><iframe type="application/pdf" :src="filePath"width="800" height="1000"></iframe></div>
<template>
<script setup>
const filePath = ref("")
<script>

五. 视频

在这里插入图片描述

  1. 支持格式:.mov,.mp4
  2. 父文件
<template><div><VideoPreviewv-if="subfix == 'mp4' || 'mov')":url="videoUrl":isExport="isExport"/></div>
</template setup>
<script>
import VideoPreview from '@/components/VideoPreview'
const subfix = ref('mp4') // 视频文件后缀
const videoUrl = ref('')
const isExport = ref(true)
</script>
  1. 组件
<template><div v-if="filePath" style="overflow-x: auto"><videooncontextmenu="return false;":src="filePath":style="`width: ${widths}% `"class="w-[218px] h-[140px] rounded-[4px] bg-second video"controlsautoplaydisablePictureInPicture:controlsList="isDownload ? 'noremoteplayback noplaybackrate' : 'noremoteplayback noplaybackrate nodownload'"><source /></video></div>
</template>
<script setup>
import dragWidthStore from '@/views/satisfiedEngineering/evaluationProcedure/store/dragWidth'
const widths = computed(() => dragWidthStore().width)
const filePath = ref('')
const isDownload = ref(false) // 是否给控件赋予下载权限
const props = defineProps({url: {type: String,default: ''},isExport: {type: Boolean,default: true,require: false}
})watch(() => props.url,newValue => {filePath.value = newValue},{ deep: true, immediate: true }
)watch(() => props.isExport,newValue => {isDownload.value = newValue},{ deep: true, immediate: true }
)
</script>

六:扩展——kkFileView

项目中没涉及到,大致记录一下

  1. 官网:https://kkfileview.keking.cn/kkFileView-4.1.0-docker.tar

  2. 支持格式
    在这里插入图片描述

  3. 组件

<!-- 文件预览支持 doc, docx, xls, xlsx, xlsm, ppt, pptx, csv, tsv, dotm, xlt, xltm, dot, dotx, xlam, xla, pages 等 Office 办公文档支持 wps, dps, et, ett, wpt 等国产 WPS Office 办公文档支持 odt, ods, ots, odp, otp, six, ott, fodt, fods 等OpenOffice、LibreOffice 办公文档支持 vsd, vsdx 等 Visio 流程图文件支持 wmf, emf 等 Windows 系统图像文件支持 psd, eps 等 Photoshop 软件模型文件支持 pdf ,ofd, rtf 等文档支持 xmind 软件模型文件支持 bpmn 工作流文件支持 eml 邮件文件支持 epub 图书文档支持 obj, 3ds, stl, ply, gltf, glb, off, 3dm, fbx, dae, wrl, 3mf, ifc, brep, step, iges, fcstd, bim 等 3D 模型文件支持 dwg, dxf, dwf, iges , igs, dwt, dng, ifc, dwfx, stl, cf2, plt 等 CAD 模型文件支持 txt, xml(渲染), md(渲染), java, php, py, js, css 等所有纯文本支持 zip, rar, jar, tar, gzip, 7z 等压缩包支持 jpg, jpeg, png, gif, bmp, ico, jfif, webp 等图片预览(翻转,缩放,镜像)支持 tif, tiff 图信息模型文件支持 tga 图像格式文件支持 svg 矢量图像格式文件支持 mp3,wav,mp4,flv 等音视频格式文件支持 avi,mov,rm,webm,ts,rm,mkv,mpeg,ogg,mpg,rmvb,wmv,3gp,ts,swf 等视频格式转码预览支持 dcm 等医疗数位影像预览支持 drawio 绘图预览Docker环境部署:网络环境方便访问docker中央仓库docker pull keking/kkfileview:4.1.0网络环境不方便访问docker中央仓库wget https://kkfileview.keking.cn/kkFileView-4.1.0-docker.tardocker load -i kkFileView-4.1.0-docker.tar -->
<template><div><iframe:src="`${containerUrl}/onlinePreview?url=` + encodeURIComponent(Base64.encode(fileUrl))"frameborder="0"class="fileView"></iframe></div>
</template><script setup>
import { Base64 } from 'js-base64'const props = defineProps({// 浏览器访问容器地址containerUrl: {type: String,default: ''},// 文档地址fileUrl: {type: String,default: ''}
})
</script>
<style lang="scss" scoped>
.fileView {width: 800px;height: 1020px;border-width: 1px;
}
</style>

相关文章:

【Vue】word / excel / ppt / pdf / 视频(mp4,mov) 预览

文件预览 Vue3一. word二. excel三. ppt四. pdf4.1 vue-pdf-embed4.2 iframe 五. 视频六&#xff1a;扩展——kkFileView Vue3 一. word 安装&#xff1a;npm install docx-preview父页面 <template><div><DocPreviewv-if"filePath.includes(docx)"…...

如何加密电脑磁盘?电脑本地磁盘加密方法介绍

随着信息技术的不断发展&#xff0c;电脑磁盘加密已经成为保护个人隐私和数据安全的重要手段。本文将介绍几种常见的电脑本地磁盘加密方法&#xff0c;帮助用户保护自己的数据安全。 文件夹只读加密专家 文件夹只读加密专家不仅可以加密电脑中的文件夹&#xff0c;还可以加密保…...

1688、淘宝、京东搜索商品聚合接口技术实现与代码示例

在当今电商领域&#xff0c;多平台商品搜索已成为用户获取多样化商品信息的重要途径。为了满足用户对1688、淘宝、京东等主流电商平台商品搜索的需求&#xff0c;开发一个跨平台的商品搜索聚合接口显得尤为重要。本文将详细介绍如何实现这一接口&#xff0c;包括接口设计、平台…...

视频智能分析平台LiteAIServer烟火识别软件引领烟火检测与识别的智能新纪元

随着人工智能技术的飞速进步&#xff0c;视频智能分析技术正以前所未有的深度和广度渗透至安全防护、环境监测等多个关键领域。其中&#xff0c;烟火识别软件LiteAIServer凭借其卓越的烟火检测与识别算法&#xff0c;成为了业界瞩目的焦点。 一、烟火检测&#xff1a;守护公共安…...

VUE前端按钮添加遮罩层

需求 当前需求是由于部分按钮操作的执行时间过长&#xff0c;因此添加遮罩层&#xff0c;防止用户误操作。 实现方式 在请求接口时创建遮罩层&#xff0c;并将遮罩层保存为全局唯一&#xff0c;请求成功或失败时&#xff0c;关闭遮罩层即可&#xff0c;切记&#xff0c;请求…...

列出机器学习方向的创新点

以下是机器学习方向的一些创新点: 一、算法创新 新型神经网络架构 图神经网络(Graph Neural Networks,GNNs) 传统的神经网络主要处理欧几里得空间的数据,如图像(网格结构)和序列(线性结构)。然而,现实世界中有许多数据具有图结构,如社交网络、分子结构等。图神经网…...

ffmpeg视频滤镜:腐蚀滤镜

滤镜简述 erosion 官网链接> FFmpeg Filters Documentation 这个滤镜会在视频上应用腐蚀操作&#xff0c;腐蚀操作是形态学中一种操作&#xff0c;接触过opencv的同学应该很熟悉。滤镜主要有如下作用&#xff1a; 去除噪声&#xff1a;腐蚀可以帮助去除图像中的小颗粒噪…...

react18中在列表项中如何使用useRef来获取每项的dom对象

在react中获取dom节点都知道用ref&#xff0c;但是在一个列表循环中&#xff0c;这样做是行不通的&#xff0c;需要做进一步的数据处理。 实现效果 需求&#xff1a;点击每张图片&#xff0c;当前图片出现在可视区域。 代码实现 .box{border: 1px solid #000;list-style: …...

java前后端项目问题总结

java前后端项目问题总结 1、字段 数据库 数据库在建表时除了需要的字段还有六个必要字段 主键 id 逻辑删 is_delete 创建人create_by 创建时间create_time 修改人 update_by 修改时间 update_time 这些字段在实体类中写法 //Date注解会自动生成一个无参构造&#xf…...

Qt设置浏览器为父窗口,嵌入播放器窗口

本项目旨在利用Qt框架实现一个创新的用户界面&#xff0c;允许将Qt窗口作为子窗口嵌入到浏览器中&#xff0c;增强用户体验并实现更丰富的交互功能。随着Web技术的不断发展&#xff0c;越来越多的应用程序希望结合桌面应用程序和Web浏览器的优势&#xff0c;以便更好地满足用户…...

运行Vue项目报错ChunkLoadError: Loading chunk 0 failed.

今天在搭建一个前后端分离的项目&#xff0c;前端报了一个问题&#xff0c;由于我不太了解前端&#xff0c;找了好多办法都没解决。因为是维护老项目&#xff0c;拿到源码大概率是没有问题的&#xff08;我也是赌的……只能按照没问题来查了&#xff09;&#xff0c;最后耐下心…...

腾讯云上基于 Apache Pulsar 的大规模生产实践

导语 Pulsar Meetup 2024 北京站已经成功落下帷幕。在本次盛会中&#xff0c;腾讯云的高级工程师韩明泽和王震江为与会者带来了精彩的演讲。他们围绕多网接入、集群迁移以及高可用最佳实践这三大核心议题&#xff0c;深入剖析了《腾讯云上基于 Apache Pulsar 的大规模生产实践…...

Linux网络:序列化与反序列化

Linux网络&#xff1a;序列化与反序列化 序列化与反序列化jsonjsoncppValue对象序列化反序列化WriterReader 序列化与反序列化 在网络通信中&#xff0c;最重要的就是通过接口&#xff0c;将数据通过网络发送给另一台主机。那么另一台主机收到数据后&#xff0c;就可以对数据进…...

Aloudata BIG 主动元数据平台支持 Oracle/DB2 存储过程算子级血缘解析

Aloudata BIG 算子级血缘主动元数据平台已经支持 Oracle 类型、DB2 类型的存储过程算子级血缘解析&#xff0c;并达到 90% 血缘解析准确率&#xff1a; 能够识别准确的字段级数据加工依赖关系&#xff1b;能够识别多级嵌套调用的存储过程的血缘&#xff1b;能够推断存储过程内…...

Java 解决阿里云OSS服务器私有权限图片通过URL无法预览的问题

简单描述一下此场景的业务: 由于系统中需要将上传的图片在系统中展示(private私有权限不能直接通过url直接展示),不想通过先下载下来然后以流的形式返回给前台展示这种方法很不友好,毕竟现在前台展示方式都是通过图片URL进行展示,所以就上官网查看API文档,果然找到了解决…...

HarmonyOS 5.0应用开发——应用打包HAP、HAR、HSP

【高心星出品】 目录 应用打包HAP、HAR、HSPModule类型HAPHAR创建HAR建立依赖HAR共享内容 HSP创建HSP建立依赖同上HSP共享内容同上 HAR VS HSP 应用打包HAP、HAR、HSP 一个应用通常会包含多种功能&#xff0c;将不同的功能特性按模块来划分和管理是一种良好的设计方式。在开发…...

Android demo文件内容记录

<style name"Theme.Demo1" parent"Theme.MaterialComponents.DayNight.DarkActionBar"><!-- Primary brand color. --><item name"colorPrimary">color/purple_500</item>//状态栏的背景色&#xff0c;优先级小于androi…...

掌握SQL高阶技巧,助你提高数据处理的效率和查询性能

高级 SQL 技巧 窗口函数&#xff08;Window Functions&#xff09; 窗口函数允许你对数据集的特定行执行计算&#xff0c;而不会聚合结果。常见的窗口函数包括&#xff1a; ROW_NUMBER()&#xff1a;为每一行分配一个唯一的序号。RANK()&#xff1a;为每一行分配一个排名&am…...

【AI服务器】全国产PCIe 5.0 Switch SerDes 测试和分析,以11槽PCIe GPU底板(PCIe 4.0/5.0)为例(二)

3 PCIe 4.0 SerDes 和 5.0 SerDes 要求比较 表 2 总结 PCIe 4.0 和 5.0 SerDes 要求之间的差 异。PCIe 标准包含三个相互依赖的规范&#xff0c;这些规范 旨在确保不同供应商的 SerDes 和通道的互操作性&#xff1a; ● PCIe BASE 规范定义了整个协议栈的芯片 级性能,是一…...

#数据结构(二)--栈和队列

栈和队列 一栈 1.栈的顺序存储结构 特点&#xff1a;先进后出 栈是一种只能在一端进行插入或删除操作的线性表。 表中允许插入删除操作的一端为栈顶&#xff08;top&#xff09;&#xff0c;表的另一端为栈底&#xff08;bottom&#xff09;&#xff0c; 1 结构体的定义 …...

内存分配函数malloc kmalloc vmalloc

内存分配函数malloc kmalloc vmalloc malloc实现步骤: 1)请求大小调整:首先,malloc 需要调整用户请求的大小,以适应内部数据结构(例如,可能需要存储额外的元数据)。通常,这包括对齐调整,确保分配的内存地址满足特定硬件要求(如对齐到8字节或16字节边界)。 2)空闲…...

linux之kylin系统nginx的安装

一、nginx的作用 1.可做高性能的web服务器 直接处理静态资源&#xff08;HTML/CSS/图片等&#xff09;&#xff0c;响应速度远超传统服务器类似apache支持高并发连接 2.反向代理服务器 隐藏后端服务器IP地址&#xff0c;提高安全性 3.负载均衡服务器 支持多种策略分发流量…...

Rust 异步编程

Rust 异步编程 引言 Rust 是一种系统编程语言,以其高性能、安全性以及零成本抽象而著称。在多核处理器成为主流的今天,异步编程成为了一种提高应用性能、优化资源利用的有效手段。本文将深入探讨 Rust 异步编程的核心概念、常用库以及最佳实践。 异步编程基础 什么是异步…...

鱼香ros docker配置镜像报错:https://registry-1.docker.io/v2/

使用鱼香ros一件安装docker时的https://registry-1.docker.io/v2/问题 一键安装指令 wget http://fishros.com/install -O fishros && . fishros出现问题&#xff1a;docker pull 失败 网络不同&#xff0c;需要使用镜像源 按照如下步骤操作 sudo vi /etc/docker/dae…...

多模态大语言模型arxiv论文略读(108)

CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文标题&#xff1a;CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文作者&#xff1a;Sayna Ebrahimi, Sercan O. Arik, Tejas Nama, Tomas Pfister ➡️ 研究机构: Google Cloud AI Re…...

html-<abbr> 缩写或首字母缩略词

定义与作用 <abbr> 标签用于表示缩写或首字母缩略词&#xff0c;它可以帮助用户更好地理解缩写的含义&#xff0c;尤其是对于那些不熟悉该缩写的用户。 title 属性的内容提供了缩写的详细说明。当用户将鼠标悬停在缩写上时&#xff0c;会显示一个提示框。 示例&#x…...

ip子接口配置及删除

配置永久生效的子接口&#xff0c;2个IP 都可以登录你这一台服务器。重启不失效。 永久的 [应用] vi /etc/sysconfig/network-scripts/ifcfg-eth0修改文件内内容 TYPE"Ethernet" BOOTPROTO"none" NAME"eth0" DEVICE"eth0" ONBOOT&q…...

【Go语言基础【13】】函数、闭包、方法

文章目录 零、概述一、函数基础1、函数基础概念2、参数传递机制3、返回值特性3.1. 多返回值3.2. 命名返回值3.3. 错误处理 二、函数类型与高阶函数1. 函数类型定义2. 高阶函数&#xff08;函数作为参数、返回值&#xff09; 三、匿名函数与闭包1. 匿名函数&#xff08;Lambda函…...

【Linux】Linux 系统默认的目录及作用说明

博主介绍&#xff1a;✌全网粉丝23W&#xff0c;CSDN博客专家、Java领域优质创作者&#xff0c;掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域✌ 技术范围&#xff1a;SpringBoot、SpringCloud、Vue、SSM、HTML、Nodejs、Python、MySQL、PostgreSQL、大数据、物…...

4. TypeScript 类型推断与类型组合

一、类型推断 (一) 什么是类型推断 TypeScript 的类型推断会根据变量、函数返回值、对象和数组的赋值和使用方式&#xff0c;自动确定它们的类型。 这一特性减少了显式类型注解的需要&#xff0c;在保持类型安全的同时简化了代码。通过分析上下文和初始值&#xff0c;TypeSc…...