layui 单图上传时,更换图片会一并上传原来的图片

是因为多了一行代码

var files = obj.pushFile(); 这段代码是将图片追加到上传对象里

上传代码:

var uploadinst = upload.render({
      elem:'#image',
      url:"{:url('upload/head')}",
      accept:"images",
      auto:false,
      bindAction:'#uploadaction',
      choose:function(obj){
        //var files = obj.pushFile();
        obj.preview(function(index, file, result){
          //uploadinst.config.elem.next()[0].value = '';
          $('#showpic').attr('src',result);
          //$('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
        });
      },
      before:function(obj){
        //layer.load();
        /*$('#showpic').cropper({
            aspectRatio: 9 / 9
        })*/
      },
      done:function(res){
        if(res.code == 200){
          layer.closeAll('loading');
          return layer.msg('上传成功');
        }else{
          return layer.msg('上传失败');   
        }
      }
     });

注销红色字体代码就好

2018-09-12 11:48:14 273人阅读 评论( 0 )