xyxiao001 / vue-cropper

A simple picture clipping plugin for vue
https://github.xyxiao.cn/vue-cropper/docs/vue3.html
MIT License
4.3k stars 695 forks source link

上传本地图片时源码中的checkImg 方法中 img.onload 一直不生效,导致 img src(unknown) #100

Closed callcter closed 6 years ago

xyxiao001 commented 6 years ago

你用在线例子看看有问题吗

callcter commented 6 years ago

在线的没有问题,但是我用的时候是这样

xyxiao001 commented 6 years ago

你怎么写的

callcter commented 6 years ago

这是全部的代码

xyxiao001 commented 6 years ago

你看看你的img传过去没

callcter commented 6 years ago
let canvas = document.createElement("canvas");
      let img = new Image();
      let rotate = 0;
      img.onload = function(){

这是 checkImg 的代码,在 img.load 之前 img 已经传进来了,但是 onload 一直都没有调用

xyxiao001 commented 6 years ago

我找上也是这样写的

xyxiao001 commented 6 years ago

线上

callcter commented 6 years ago

这就是线上的代码,我这边就是不管用,之前是没有问题的,代码我觉着也没有问题 T_T

xyxiao001 commented 6 years ago

你直接传图片地址进去是可以的嘛,只有本地上传有问题吗

callcter commented 6 years ago

貌似也不行,还是没有调用

VueCropper(
        ref='cropper',
        img='http://ofyaji162.bkt.clouddn.com/bg2.jpg',
        outputType='png',
        :autoCropWidth='crop_opt_width',
        :autoCropHeight='crop_opt_height',
        :autoCrop='crop_opt_auto',
        :fixedBox='crop_opt_fixed',
        :canMoveBox='crop_opt_boxmove',
        :canScale='crop_opt_scale',
        :info='crop_opt_info')
xyxiao001 commented 6 years ago

那就是代码问题的, 你用vue看看组件里面的属性

callcter commented 6 years ago

我找一下问题吧,找到跟你说一声

callcter commented 6 years ago

找到问题了,项目里面还用到了 zrender,把 new Image()方法覆盖了,生成了一个ZImage(),所以 onload 失效,我改成了

img = document.createElement('img')

来创建 img 对象