掘友等级
获得徽章 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
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="元"
下一页