获得徽章 17
前端 @航运
前端 @航运
通过url下载文件方法export const downloadFileByUrl = async (url: string, isCurrentSite: boolean, onDownloadProgress?: (p?: string | number) => void, fileName?: string) => {
let _fileUrl = url
if (isCurrentSite) {
const temp = new URL(url)
_fileUrl = temp.pathname + temp.search
}
const fileBlob = await axiosInstance.get(_fileUrl, {
responseType: 'blob',
returnType: 'axios',
onDownloadProgress(event) {
onDownloadProgress?.(event.total ? event.loaded / event.total * 100 : 0)
},
})
downloadFileByBlob(fileBlob.data, fileName || fileBlob.headers.filename || fileBlob.headers?.['content-disposition']?.match?.(/filename=(.*)/)?.[1] || '下载')
}
展开
评论
在循环的方法中 for循环的效率最高 其次是for of foreach for in
3
forEach循环的时候无法终止
评论
iframe嵌入其他页面且需要自动登录的时候、可以加个id的随机数、这样可以解决很多页面缓存与cookie缓存的问题
评论
获取子目录的信息可以这么 获取const files = require.context('./childRoutes', true, /\.ts$/)
const routeMap: any = []
files.keys().forEach(key => {
const child = files(key).default
routeMap.push(child)
})
展开
评论
webpack开启多线程常用的是thread-loader 在options里面配置workers: 3,就是开启三个
评论
推荐一个好用的svg Icon组件unplugin-icons/webpack 配好之后可以随心所欲更改svg的颜色Icons({
scale: 1,
jsx: 'react',
compiler: 'jsx',
customCollections: {
svg: FileSystemIconLoader('./src/assets/icons/svg'),
colour: FileSystemIconLoader('./src/assets/icons/colour')
},
transform(svg, collection) {
const out = svg
.replace(/(<svg[^>]+)(width=['"][^'"]+['"]+)/g, '$1')
.replace(/(<svg[^>]+)(height=['"][^'"]+['"]+)/g, '$1')
.replace(/<svg/, '<svg style="vertical-align: middle;"')
return collection === 'svg'
? out
.replace(/(?<=<path (?!class="not-main")[^>]*)fill="(?!none)[^"]*"/g, 'fill="currentColor"')
.replace(/(?<=<rect (?!class="not-main")[^>]*)(?<=(stroke|fill)=)"(?!none)[^"]*"/g, '"currentColor"')
: out
}
}),
展开
评论
antdesign input输入框 前缀可以用prefix="¥" 后缀可以用suffix="元"
5
关于位移运算符 左移操作符(<<)、“有符号”右移操作符(>>)、“无符号”右移操操作符(>>>)三种
评论
使用JSON操作的时候记得空值处理、 不然会报错
评论
antdesign upload上传文件默认的过滤可以通过选择所有文件绕过去、这个时候可以用beforeUpload做一次二次校验 beforeUpload(file: any) {
if (type) {
const isPass = checkFileMineType(file, type)
if (messageTip && !isPass) {
message.error('文件格式错误,请添加正确格式的文件(.xlsx或.xls的文件)')
return LIST_IGNORE
}
if (!isPass) {
message.error('文件类型不符合要求')
return LIST_IGNORE
}
}
if (file.size > maxSize.size) {
message.error(maxSize.message || '超出文件大小限制')
return LIST_IGNORE
}
if (maxSizeWH) {
return getFileWidthAndHeight(file, maxSizeWH?.[0], maxSizeWH?.[1])
}
return file
},
展开
评论
mac虚拟机Parallels Desktop这个挺好用的 也有破解版可以解决mac需要很多window系统的软件安装测试、
评论
ahooks useRequest的manual: true默认不请求、需要run一下 如果配置为false 则默认会执行一次
5
数组转为对象key value的方法
export const toObject = (pairs)=> {
let newArr = {}
pairs?.map(itm=>{
if (itm?.dictKey) {
newArr[itm.dictKey] = itm.dictValue
}
})
return newArr
}
展开
评论
下一页
个人成就
文章被点赞 127
文章被阅读 61,538
掘力值 1,321
收藏集
11
关注标签
7
加入于