博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
图片上传
阅读量:6871 次
发布时间:2019-06-26

本文共 1721 字,大约阅读时间需要 5 分钟。

this.$nextTick(function() {
let _self = this; $(this.$el).on('change', 'input[type="file"]', function() {
// 判断图片类型 const rFilter = /^(?:image\/jpeg|image\/png|image\/bmp)$/i; const imgFile = this.files[0]; if(!imgFile) return; const _this = this; const reader = new FileReader(); reader.onload = function(e){
const data = e.target.result; const image = new Image(); image.src = data; image.onload = function(){
const width = image.width; const height = image.height; if(width != 1029 || height != 270){
$(_this).val(''); return globalBus.$emit('warning', '尺寸需要1029*270哦!'); }else{
if(rFilter.test(imgFile.type)){
// 判断图片大小,通过max-size传值,100kb if(Math.ceil(imgFile.size / 1024) < _self.maxSize){
common.ajax({
target: $(_self.$el), url: DI.common.upload, success: function(data){
if(data.retCode == 0){
const info = data.data; console.log(info); _self.$emit('input', info) }else{
globalBus.$emit('warning', data.retMsg); } } }, true) }else{
$(_this).val(''); globalBus.$emit('warning', '图片大小不能超过' + _self.maxSize + 'Kb'); } }else{
$(_this).val(''); globalBus.$emit('warning', '商品图片格式需要上传jpg,png,bmp哦'); } } } } reader.readAsDataURL(imgFile); }); });

转载于:https://www.cnblogs.com/landofpromise/p/7403332.html

你可能感兴趣的文章
向量样本【模式识别】感知器 Perceptron
查看>>
委托杂谈
查看>>
《Android内核剖析》读书笔记 第7章 理解Context
查看>>
IOS开发之UILabel动态高度设置方法
查看>>
儿子购买的书
查看>>
让Android中的webview支持页面中的文件上传
查看>>
hbase regionserver挂掉的问题
查看>>
延迟段创建的学习-实验
查看>>
C/C++ 内存对齐
查看>>
php 在函数内引用全局变量 讲解引用
查看>>
数据结构和算法系列1 线性表之顺序表
查看>>
项目经理的指导
查看>>
android蓝牙开发---与蓝牙模块进行通信
查看>>
HDU 3537 Daizhenyang's Coin(博弈,翻硬币)
查看>>
数据结构和算法系列5 七大排序之冒泡排序和快速排序
查看>>
2013年8月3日第31周六
查看>>
Android使用隐藏api的方法(使用被@hide的api)
查看>>
Robert Penner's Easing Functions
查看>>
Parallel for loops in .NET C# z
查看>>
mysql alter修改字段的长度 类型sql语句
查看>>