Vue.js 头像上传组件:图片格式和大小限制
<script type='module'> const instance = axios.create({ baseURL: 'http://localhost:8080', timeout: 1000, }) new Vue({ el: '#app', dataType: 'json', data: { imageUrl: '' }, methods: { handleAvatarSuccess(res, file) { this.imageUrl = URL.createObjectURL(file.raw); }, beforeAvatarUpload(file) { const isJPG = file.type === 'image/jpeg'; const isLt2M = file.size / 1024 / 1024 < 2; if (!isJPG) { this.$message.error('上传头像图片只能是 JPG 格式!'); } if (!isLt2M) { this.$message.error('上传头像图片大小不能超过 2MB!'); } return isJPG && isLt2M; } }, created() { } });
 
原文地址: https://www.cveoy.top/t/topic/pcYf 著作权归作者所有。请勿转载和采集!