当前位置:网站首页>JS get the suffix format of a file name
JS get the suffix format of a file name
2022-07-19 01:29:00 【Pengzai studio】
vue In the project , Attachment upload has always been to upload pictures ,jpg、png、bmp Wait for the format of the picture , For preview, just use a picture preview plug-in , But some time ago , The customer needs to upload pdf、word And realize preview .
Ah … Is this H5 project , Mobile upload pdf、word file , I want to say that if you can find the corresponding file ???
Uploading is nothing , Just like the picture , The most I can do is upload and add a few more formats for validation , Mainly when the page preview is displayed , I need to know what file format it is ( Let the picture in the page directly display the small picture and click to enlarge ,word and pdf Page shows “ see ” Button , Click on to execute the preview pop-up ), After all, pictures 、word、pdf Preview method is different , Different plug-ins , So I simply wrote a js To get the suffix , Use suffixes to achieve the effect I want .
Place the bottom js writes methods in
// Get file suffix
getFileType(val){
return val.substring(val.lastIndexOf(".") + 1);
}
Used on the page
getFileType(name)
You can get the suffix , Because when I upload storage ,name What is stored is the file name + postfix form ( Such as aaa.jpg、 A high school student .pdf etc. ), So send it directly name that will do .
Get suffix format , Can achieve the effect I want .
边栏推荐
- 【ElenmentUI el-date-picker日期选择器,结束时间不得早于开始时间,且只能选择距开始时间指定天数的日期】
- 正则,JWT token,容联云,celery,频道组,SKU,SPU,request对象的属性和方法的补充知识
- Eye of depth III - (7)] mathematics: application of SVD decomposition
- Summary of Applied Cryptography
- uni canvas截取图片
- “我的”Bug大全(转载)
- From catf1ag two-hour AK match pwn/attack killing, summarize the common command guide of emergency response
- js字符串转对象 js对象转字符串 js字符串与对象互转
- If the website is hacked, what if you jump to other websites through Baidu / Sogou and other search keywords?
- extern和static的区别
猜你喜欢
随机推荐
量化行业知识汇总
The C Programming Language 2nd --笔记--6.7
智能指针(shared_ptr、unique_ptr、weak_ptr)
两表连接进行增删改查
Collection and summary of penetration test information
uni-app微信公众号(5)——新增、修改地址
es可选链
缤纷彩色文字广告代码,文字广告代码美化版,给网站添加文字广告教程
Maker-鸿蒙应用开发培训笔记03
MoveIt2——4.机器人模型和机器人状态
Registry hijacking triggers malicious programs
object-fit:cover;在小程序中不起作用,小程序图片变形了如何处理
Maker-HarmonyOS应用开发培训笔记01
JSX 语法
鼠标右键菜单添加快速打开选项遇见的错误:
Add, delete, modify and check the connection between the two tables
Day06 ORM field and operation
【ElenmentUI el-date-picker日期选择器,结束时间不得早于开始时间,且只能选择距开始时间指定天数的日期】
服务器如何安装宝塔面板?(宝塔面板安装教程)
Day10 front back continuous adjustment








![Buuctf [bjdctf2020]ezphp1 detailed explanation](/img/10/d2593dff2f4a5f0ca41a9f651128df.png)