欢迎扫码,加作者微信

Compressor.js前端图片压缩

2022-08-01 18:40:13
2025-06-20 18:55:46

引用方法

Vue3

shell 复制代码
npm i -S compressorjs
shell 复制代码
import Compressor from 'compressorjs';

使用方法

js 复制代码
import axios from 'axios';
import Compressor from 'compressorjs';

document.getElementById('file').addEventListener('change', (e) => {
  const file = e.target.files[0];

  if (!file) {
    return;
  }

  new Compressor(file, {
    quality: 0.6,
    success(result) {
      const formData = new FormData();
      formData.append('file', result, result.name);
      axios.post('/path/to/upload', formData).then(() => {
        console.log('Upload success');
      });
    },
    error(err) {
      console.log(err.message);
    },
  });
  
});

常见问题

文章目录

运营需要亿点资金维持,您的支持,是小白龙创作的动力!!!

生成中...

扫码赞赏

感谢您的支持与鼓励

安全支付

支付赞赏

您的支持是我们前进的动力

留言
快捷金额
自定义金额
¥

安全保障

采用银行级加密技术,保障您的支付安全

暂无评论,欢迎留下你的评论
暂无评论,期待您的精彩留言!
Copyright © 2025 粤ICP备19043740号-1
🎉 今日第 1 位访客 📊 年访问量 0 💝 累计赞赏 1000+