1.
const fileName = this.form.fileName + '.pdf'
const xhr = new window.XMLHttpRequest()
xhr.open('GET', fileUrl, true)
xhr.responseType = 'blob'
xhr.onload = () => {
const url = window.URL.createObjectURL(xhr.response)
const a = document.createElement('a')
a.href = url
a.download = fileName
a.click()
}
xhr.send()
2.
const pattern=/[`~!@#$^\-&*()=|{}':;',\\\[\]\.<>\/?~!@#¥……&*()——|{}【】';:""'。,、?\s]/g
str = str.replace(pattern,'')
str.replace(/(^\s*)/g, '')
str.replace(/(\s*$)/g, '')
str.replace(/[ ]/g, '')
str.replace(/(^\s*)|(\s*$)/g, '')
str.trim()
str.replace(/\s+/g, '')
3.
border-image: linear-gradient(to right, #8f41e9, #578aef) 4;
4.
html.gray-mode {
filter: grayscale(.95);
-webkit-filter: grayscale(.95);
}
html {
position: relative;
width: 100%;
height: 100%;
overflow: scroll;
background: #fff;
}
html::before {
content: "";
position: absolute;
inset: 0;
backdrop-filter: grayscale(95%);
background: rgba(0, 0, 0, 1);
mix-blend-mode: color;
z-index: 10;
pointer-events: none;
}
5.
.common-style {
display: inline-block;
height: 28px;
line-height: 26px;
padding: 0 10px;
font-size: 12px;
border-radius: 5px;
}
.warnStatus {
.common-style();
color: #5A9BFA;
background: #ecf5ff;
border: 1px solid #e0efff;
}
6.
if(body.clientHeight + body.scrollTop == body.scrollHeight) {
console.log('已滚动到底部')
}
7. 原生js 拖动
参考链接 https://juejin.cn/post/7171269067729272868
8. 快速排序
function sortArray(nums) {
quickSort(0, nums.length - 1, nums);
return nums;
}
function quickSort(start, end, arr) {
if (start < end) {
const mid = sort(start, end, arr);
quickSort(start, mid - 1, arr);
quickSort(mid + 1, end, arr);
}
}
function sort(start, end, arr) {
const base = arr[start];
let left = start;
let right = end;
while (left !== right) {
while (arr[right] >= base && right > left) {
right--;
}
arr[left] = arr[right];
while (arr[left] <= base && right > left) {
left++;
}
arr[right] = arr[left];
}
arr[left] = base;
return left;
}