序言 👏
描述
主要提供大量对 dom 操作的封装。
# npm 使用方式
const { Dom } = 'sf-utils2'
// 不推荐使用 解构函数, 因为会里面逻辑大量用了this,如果解构了,this会导致指向错误问题
// 如下例子
const { downloadFile } = Dom // 这样方式
const url = 'https://info.compassedu.hk/ad/225/1637553399694.png?imageView2/3/q/100|imageslim'
Dom.downloadFile({ url, filename: `${Date.now()}.png` }).then(() => {
alert('下载成功!')
})
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
提示
不推荐使用 解构函数, 因为会里面逻辑大量用了 this,如果解构了,this 会导致指向错误问题
# cdn 使用方式
<script src="https://cdn.jsdelivr.net/npm/sf-utils2/lib/b-utils.min.js"></script>
<script>
const Dom = window.sfutils.Dom // 这样方式
const url = 'https://info.compassedu.hk/ad/225/1637553399694.png?imageView2/3/q/100|imageslim'
Dom.downloadFile({ url, filename: `${Date.now()}.png` }).then(() => {
alert('下载成功!')
})
</script>
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
上次更新: 2025/07/01, 14:52:29