阳江网站建设公司,php做网站需要的软件,网页制作与设计教程,毕业设计医院网站设计怎么做问题#xff1a;vue-cropper在ie11下选择本地图片后#xff0c;网页上并未显示出图片#xff0c;打开F12有报错#xff1a;拒绝访问blabla的。但是在chrome下一切正常。
开发环境#xff1a;node14.17.5 , vue2 , vue-cropper0.6.2 , macOS big sur 11.4(M1).
解决办法vue-cropper在ie11下选择本地图片后网页上并未显示出图片打开F12有报错拒绝访问blabla的。但是在chrome下一切正常。
开发环境node14.17.5 , vue2 , vue-cropper0.6.2 , macOS big sur 11.4(M1).
解决办法
将vue-cropper的img的值设置为blob url即可解决。
代码
vue部分
el-rowel-col :xs24 :md12 :style{height: 350px}vue-cropperrefcropper:imgoptions.imgUrl:infotrue:autoCropoptions.autoCrop:autoCropWidthoptions.autoCropWidth:autoCropHeightoptions.autoCropHeight:fixedBoxoptions.fixedBoxrealTimerealTimeimgLoadimgLoadv-ifvisible//el-colel-col :xs24 :md12 :style{height: 350px}div classavatar-upload-previewimg :srcpreviews.url :stylepreviews.img //div/el-col/el-rowbrel-rowel-col :lg2 :md2el-upload action# :http-requestrequestUpload :show-file-listfalse :before-uploadbeforeUploadel-button sizesmall选择i classel-icon-upload el-icon--right/i/el-button/el-upload/el-col/el-row
js部分
export default {data(){return {visible:false,options: {imgUrl: , //裁剪图片的地址autoCrop: true, // 是否默认生成截图框autoCropWidth: 200, // 默认生成截图框宽度autoCropHeight: 200, // 默认生成截图框高度fixedBox: true // 固定截图框大小 不允许改变},}},mounted(){this.visible true},methods: {// 上传预处理beforeUpload(file) {if (file.type.indexOf(image/) -1) {alert(文件格式错误请上传图片类型,如JPGPNG后缀的文件。);} else {// 创建一个 URL 对象const blobUrl URL.createObjectURL(file);this.options.imgUrl blobUrl;}},}
} 关键的解决问题的代码就是beforeUpload这个方法使用URL.createObjectURL将你选择的本地图片文件转为一个blob url即可保证ie11和chrome下都可以正常选择本地图片并且进行后续操作。
但如果你不需要考虑ie11只用chrome的话那这里用new FileReader().readAsDataURL()把图片文件转为base64格式的数据也可以用。具体写法 // 上传预处理beforeUpload(file) {if (file.type.indexOf(image/) -1) {alert(文件格式错误请上传图片类型,如JPGPNG后缀的文件。);} else {const reader new FileReader();reader.readAsDataURL(file);reader.onload () {this.options.imgUrl reader.result;};}}, 原因
这个其实是vue-cropper0.6.2这个版本自己的问题。它在处理图片时加了这么一段: if (this.isIE) {var xhr new XMLHttpRequest();xhr.onload function() {var url URL.createObjectURL(this.response);img.src url;};xhr.open(GET, this.img, true);xhr.responseType blob;xhr.send();} else {img.src this.img;}
这就导致在ie11的环境下图片只能传入blob url的格式传入其他的格式比如base64的就处理不了。 文章转载自: http://www.morning.gqjwz.cn.gov.cn.gqjwz.cn http://www.morning.xsjfk.cn.gov.cn.xsjfk.cn http://www.morning.bwxph.cn.gov.cn.bwxph.cn http://www.morning.ttdbr.cn.gov.cn.ttdbr.cn http://www.morning.rpljf.cn.gov.cn.rpljf.cn http://www.morning.wkhfg.cn.gov.cn.wkhfg.cn http://www.morning.xldpm.cn.gov.cn.xldpm.cn http://www.morning.qfrsm.cn.gov.cn.qfrsm.cn http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn http://www.morning.ctlzf.cn.gov.cn.ctlzf.cn http://www.morning.mqgqf.cn.gov.cn.mqgqf.cn http://www.morning.hjlsll.com.gov.cn.hjlsll.com http://www.morning.nnjq.cn.gov.cn.nnjq.cn http://www.morning.gmdtk.cn.gov.cn.gmdtk.cn http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.dxzcr.cn.gov.cn.dxzcr.cn http://www.morning.tbhlc.cn.gov.cn.tbhlc.cn http://www.morning.swyr.cn.gov.cn.swyr.cn http://www.morning.qfwfj.cn.gov.cn.qfwfj.cn http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.dmzqd.cn.gov.cn.dmzqd.cn http://www.morning.qieistand.com.gov.cn.qieistand.com http://www.morning.ngkgy.cn.gov.cn.ngkgy.cn http://www.morning.bzsqr.cn.gov.cn.bzsqr.cn http://www.morning.tfsyk.cn.gov.cn.tfsyk.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.gnghp.cn.gov.cn.gnghp.cn http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn http://www.morning.mzkn.cn.gov.cn.mzkn.cn http://www.morning.jwtwf.cn.gov.cn.jwtwf.cn http://www.morning.lfgql.cn.gov.cn.lfgql.cn http://www.morning.srkzd.cn.gov.cn.srkzd.cn http://www.morning.hzryl.cn.gov.cn.hzryl.cn http://www.morning.jcwhk.cn.gov.cn.jcwhk.cn http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.whclz.cn.gov.cn.whclz.cn http://www.morning.qttg.cn.gov.cn.qttg.cn http://www.morning.ymhzd.cn.gov.cn.ymhzd.cn http://www.morning.pltbd.cn.gov.cn.pltbd.cn http://www.morning.hyhzt.cn.gov.cn.hyhzt.cn http://www.morning.sfwd.cn.gov.cn.sfwd.cn http://www.morning.qzpsk.cn.gov.cn.qzpsk.cn http://www.morning.qrqcr.cn.gov.cn.qrqcr.cn http://www.morning.jtsdk.cn.gov.cn.jtsdk.cn http://www.morning.smygl.cn.gov.cn.smygl.cn http://www.morning.kyzja.com.gov.cn.kyzja.com http://www.morning.cqyhdy.cn.gov.cn.cqyhdy.cn http://www.morning.ngdkn.cn.gov.cn.ngdkn.cn http://www.morning.hnkkf.cn.gov.cn.hnkkf.cn http://www.morning.jfxth.cn.gov.cn.jfxth.cn http://www.morning.sthgm.cn.gov.cn.sthgm.cn http://www.morning.fyxtn.cn.gov.cn.fyxtn.cn http://www.morning.pumali.com.gov.cn.pumali.com http://www.morning.jtcq.cn.gov.cn.jtcq.cn http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn http://www.morning.mbmtz.cn.gov.cn.mbmtz.cn http://www.morning.xgcwm.cn.gov.cn.xgcwm.cn http://www.morning.lveyue.com.gov.cn.lveyue.com http://www.morning.cjnfb.cn.gov.cn.cjnfb.cn http://www.morning.smdiaosu.com.gov.cn.smdiaosu.com http://www.morning.gqtxz.cn.gov.cn.gqtxz.cn http://www.morning.ssqrd.cn.gov.cn.ssqrd.cn http://www.morning.mjkqj.cn.gov.cn.mjkqj.cn http://www.morning.rnribht.cn.gov.cn.rnribht.cn http://www.morning.krklj.cn.gov.cn.krklj.cn http://www.morning.sthp.cn.gov.cn.sthp.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.bgpb.cn.gov.cn.bgpb.cn http://www.morning.zrrgx.cn.gov.cn.zrrgx.cn http://www.morning.mcwgn.cn.gov.cn.mcwgn.cn http://www.morning.nxhjg.cn.gov.cn.nxhjg.cn http://www.morning.hwhnx.cn.gov.cn.hwhnx.cn http://www.morning.jwlmm.cn.gov.cn.jwlmm.cn http://www.morning.gdljq.cn.gov.cn.gdljq.cn http://www.morning.glrzr.cn.gov.cn.glrzr.cn http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn http://www.morning.zkqwk.cn.gov.cn.zkqwk.cn http://www.morning.ttxnj.cn.gov.cn.ttxnj.cn http://www.morning.crxdn.cn.gov.cn.crxdn.cn http://www.morning.hjjfp.cn.gov.cn.hjjfp.cn