Giter VIP home page Giter VIP logo

vue-img-inputer's Introduction


vip


GitHub release poi Bili


点击查看中文文档 | Have a glance at Demo


Intro

  • <input type="file" /> like, only support single image
  • auto-upload support
  • drop-select / preview / use as <img /> as well
  • optional skins

Screenshots


Install and Usage

npm install vue-img-inputer
import ImgInputer from 'vue-img-inputer'
import 'vue-img-inputer/dist/index.css'

Vue.component('ImgInputer', ImgInputer)
<img-inputer v-model="file" theme="light" size="large"/>

API

Auto upload related
  1. auto-upload: Boolean
    set to enable auto-upload

  2. action: String
    request URL

  3. upload-key: String
    default: file
    key name in form-data

  4. extra-data: Object
    extra data been appended in request's form-data

  5. headers: Object
    additional headers of request

  6. with-cookie: Boolean
    whether cookies will been sent

  7. on-start: Function
    params: func ( file )
    hook function when upload start

  8. on-progress: Function
    params: func ( event, file )
    hook function when uploading, get progress by event.percent

  9. on-success: Function
    params: func ( res, file )
    hook function when upload success, res is response from server

  10. on-error: Function
    params: func ( err, file )
    hook function when upload failed


Input tag related
  1. accept: String
    default: image/*,video/*;
    suggest to set a specific value like image/jpg,image/gif; for wildcard will lead to a serious delay

  2. placeholder: String
    default: Drop file here or click

  3. id: String
    default: random string in 4 length
    id of input tag

  4. readonly: Boolean

  5. capture: Boolean
    default: false
    whether use camera directly in mobile

  6. max-size: Number
    default: 5120
    max-size of image (KB)

  7. name: Boolean
    name of input tag

  8. any input's attribute
    any input's original attributes set on component will be inherited by inner input tag


UI related
  1. img-src: String
    image resource let component behavior like <img />

  2. theme: String
    default: material two themes optional (light / material)

  3. size: String small / normal / large

  4. icon: String
    clip / img / img2

  5. ali-icon: String
    if you use iconfont.cn, set unicode of any icon to custom

  6. no-mask: Boolean
    remove mask when hover

  7. no-hover-effect: Boolean
    remove all hover effect (include text) when hover

  8. bottom-text: String
    default: Drop file here or click to change
    text in the bottom when hover

  9. no-multiple-text: String
    default: Not support multiple files
    visible only the state is readonly, cover bottom-text

  10. exceed-size-text: String
    default: The size of file should less than: ${maxSize}
    visible only the state is readonly, cover bottom-text

  11. no-action-text: String
    default: Action hasn't set up yet
    visible only the state is readonly, cover bottom-text

  12. readonly-tip-text: String
    default: Readonly
    visible only the state is readonly, cover bottom-text


Events
  1. onChange: Function
    params: func ( file, fileName )
    hook function when file selected

  2. onExceed: Function
    params: func ( file )
    hook function when file exceed max-size


Methods
  1. reset
    reset componet but will not clear img-src

vue-img-inputer's People

Contributors

egoist avatar sinchang avatar wayne-mai avatar waynecz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-img-inputer's Issues

求教

你好,请问在 vue-img-inputer这个项目里,你引用这个组件的父组件是哪个,在哪里放,因为 git 代码里有几处父子组件交互的地方我看不太懂,所以想找到你的父组件

无法起来项目

我克隆之后,npm install ,之后 npm start ,出现cannot get

兄弟,问你一个关于上传相关的问题?!

我在handleFileChange这个方法加了一个upLoad方法,如下:

        handleFileChange (e) {
          this.upLoad(this.file)
          console.log(this)  //这里的this在控制台里看到的fileUp是有值的
          console.log(this.fileUp) //第一次这里打印出来的fileUp是空字符串
          // 双向绑定
          this.$emit('input', this.file);
          // 文件选择回调 && 两种绑定方式
          this.onChange && this.onChange(this.file, this.file.name,this.fileUp);
         
          this.$emit('onChange', this.file, this.file.name,this.fileUp);
         
          this.imgPreview(this.file);
 
          this.fileName = this.file.name;
 
          this.isActive = false

          this.resetInput();
        })

请问你知道什么原因吗?

图片设置maxSize的时候报错信息被遮挡

我给组件设置样式为宽高各60,我看源码给的错误提示是width是100%,但是提示文字超过了60px,被组件遮挡住了一部分,麻烦看一下

而且我想重置内部的样式只能通过改源码,而没办法自定义

多个图片上传支持吗

请问上传一个照片之后,可以出现一个新的选择图片的地方,支持上传多涨图片吗

如何设置界面的大小

大神你好,正如我在另一个问题提到的一样,我想实现如图所示的效果
image

即图片大小是60*60,图片下方是使用你的组件实现的,但是我发现只能通过 size设置small 、normal和large,能否自定义大小呢?谢谢

初始图片

请问插件的初始图片怎么设置,是不是用imgSrc设置,为什么我设置了显示不出来

image

变成了这样子

image

我图片地址是没问题的

建议加上一个type,并且在onchange事件里面可以取到此type

兄弟你好,我现在要做多张图片上传功能,比如身份证或者是行驶证,或者是些其他的证件,我需要将这些不同的type传给后端,我建议在props里面可以支持从外界传入一个type,并且在onchange事件里面可以让我取到这个type

请教一下启动报错!

npm install 后
npm run start 报错
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node build/dev-server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

求教一下是什么原因,谢谢!

当imgSrc为动态数据时,页面不渲染

如题,当传入的参数 :imgSrc="item.list_image" 时,item.list_image是ajax返回的数据,页面只渲染了组件,组件内的图片,并没有渲染,请问这个问题怎么解决比较好呢?

我尝试了一下加一个v-if的判断:
<imgInputer v-if="item.list_image" v-model="file" accept="image/*" :imgSrc="item.list_image" @onchange="fileChange">
这样是可行的,这样整个组件会等待ajax返回后再渲染,请问还有更优雅一点的方式吗?

请问后台返回的图片可以作为预览图吗

`<div class="nick f-pr">
          <span>昵称:</span><input type="text" placeholder="请输入用户昵称" v-model="nick_name"/>
          <div class="avatar f-pa" :style="{background: 'url(' + userInfo.avatar + ')'}">
            <VueImgInputer v-model="picValue" theme="light" size="small" placeholder="" accept="image/*" icon="false">
            </VueImgInputer>
          </div>
        </div>`

userInfo.avatar这张图是后台返回的,我想作为预览图

打开文件选择器是如何实现的

大神好,我看了组件原码,在组件生成的html代码中,已经把input(type=file)的标签放到-9999了,响应点击打开文件选择窗口的行为是怎么实现的?

上传参数配置问题

大神你好,

我在用 auto-upload 做图片上传的时候是这样写的

        <el-table-column
          prop="coverurl"
          label="书籍封面"
          sortable
          width="180" header-align="center">

          <template slot-scope="scope">
            <!--  <img  :src="scope.row.coverurl" alt="" style="width: 70px;height: 70px">
             -->
            <img-inputer 
                action ="http://localhost:8081/article/uploadimg"  
                headers="{ 'Content-Type': 'multipart/form-data'}" 
                v-model="file" theme="light" size="small" 
                auto-upload 
                :imgSrc="scope.row.coverurl" 
                accept="image/jpeg,image/png"/>
          </template>
        </el-table-column>

然后运行就会提示 XMLHttpRequest cannot load http://localhost:8081/article/uploadimg. Response for preflight is invalid (redirect)
这个提示应该属于跨域问题吧,这个问题怎么解决呢

朋友你好,动态添加imgInputer , 删除后渲染有问题

#关键代码:

<div v-for="(item,index) in fileList">
      <imgInputer v-model="item.file" accept="image/*" @onChange="fileChange"/>
      <button type="button" @click="remove(fileList,index)">remove</button>
</div>
<button type="button" @click="add">add</button>


   methods: {
      fileChange(file, name) {
        console.log('File:', file);
        console.log('FileName:', name);
     },
      add(){
        this.fileList.push({
          file:null
        })
      },
      remove(item,index){
        item.splice(index,1)
      }
    }

描述:
当我执行add()方法后,fileList = [{file:null},{file:null}],添加图片以后fileList = [{file:file1},{file:file2}],如果执行remove()删除file1,数据正常删除,但是页面上没有实时渲染

如何上传图片

组件装好了,组件上有个v-model属性,我该怎么连同表单一起上传文件呢?

移动端拍照上传多张图片会出错

html部分

  <div class="photoarea-outer">
        <form action="" enctype="multipart/form-data" method="post">
        <div class="photoarea f-cb">
          <VueImgInputer v-model="picValue1" theme="light" size="small" placeholder="" accept="image/*" icon="true" class="image-insert f-fl" noMask :capture="false">
          </VueImgInputer>
          <VueImgInputer v-model="picValue2" theme="light" size="small" placeholder="" accept="image/*" icon="true" class="image-insert f-fl" noMask :capture="false">
          </VueImgInputer>
          <VueImgInputer v-model="picValue3" theme="light" size="small" placeholder="" accept="image/*" icon="true" class="image-insert f-fl" noMask :capture="false">
          </VueImgInputer>
        </div>
        </form>
      </div>

js部分,提交信息给后台

var picTimer = setInterval(() => {
            if (pic1Finish && pic2Finish && pic3Finish) {
              let postData = new FormData();
              postData.append('file1', self.picValue1);// 绑定的图片值
              postData.append('file2', self.picValue2);// 绑定的图片值
              postData.append('file3', self.picValue3);// 绑定的图片值
              postData.append('token', global.searchLocalStorage('XTSY_token')); 
              postData.append('comment', self.desc);
              postData.append('orderId', self.$route.query.orderId);
              postData.append('goodsId', self.$route.query.goodsId);
              postData.append('goodsStocksId', self.$route.query.goodsStocksId);
              postData.append('status', self.starNum);
              postData.append('flag', self.flag);
              global.requestData('post', '/xituApi/api/GoodsCommentAPI/save', postData, (res) => {
                res = res.data;
                if (res && res.code === 1) {
                  swal({
                    title: '评价成功!',
                    showConfirmButton: false,
                    timer: 500
                  });
                  setTimeout(() => {
                    self.loadingVisible = false;
                    self.$router.go(-1);
                  }, 1000);
                } else if (res && res.code === 422) {
                  global.jumpToLogin();
                } else {
                  swal({
                    title: res.msg
                  });
                }
              }, () => {
                swal({
                  title: '通信失败!'
                });
              });
              clearInterval(picTimer);
            }
          }, 100);

用拍照的方式上传三张图片出错,在相册里面选择照片上传是正常的。

如何主动触发点击事件?

有一个页面,希望在快捷入口进入时,不需要用户点击上传按钮就打开上传框。

意思就是这个页面加载的时候,就主动触发一次组件的click事件,要如何做?

  mounted() {
    if (this.$route.params.pickImage) {
      this.$refs.$image.$el.click();
    }
  },

现在这样 并不行

大神你好,我在使用时遇到了一些问题,想请教一下

我目前的情况是,在某个页面中使用了三次vue-img-inputer组件,因为功能需求是一次性上传三张图片。三个组件用form表单包裹,然后出现了一个奇怪的问题。1、若使用一次组件,那么使用正常。2、使用三次组件,通过相册上传图片正常。3、使用三次组件,通过摄像头拍张上传失败。此时调用Vue.http是直接进入报错函数了,无法向服务器发起请求。我目前的手机系统是ios10.2。
求大神指教......

chrome点击上传打开弹窗大概要10s

chrome点击上传打开弹窗大概要10s, 在iview里面使用并且报错
··
Property or method "back" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components
··
··
[Vue warn]: Invalid handler for event "click": got undefined
··

拖拽上传无法获取文件名

demo 上测试:

  • 使用点击上传
document.getElementById('wddvm').value
"C:\fakepath\lifecycle.png"
  • 拖拽上传
document.getElementById('8h5cb').value
"" // 返回空

另外建议把 demo 的源码也传到 GitHub,便于他人 pr 时调试。

获取不到文件数据啊

我使用这个组件上传,如下

qq 20170911161753

data() { return { corpInfo:{ logo:'', }, uploadFileData:null,

但是获取到的文件数据(uploadFileData)是空啊{}

当imgSrc为动态数据时,页面不渲染

如题,当传入的参数 :imgSrc="item.list_image" 时,页面只渲染了组件,组件内的图片,并没有渲染,请问这个问题怎么解决比较好呢?

我尝试了一下加一个v-if的判断:

关于v-model动态绑定的问题

您好,我根据后台返回的图片数量来生成VueImgInputer组件,比如后台返回的数据
images{ 1 : "/images/2017/11/06/1509948936565.png" 2 : "/images/2017/11/06/1509948936610.PNG" 3 : "/images/2017/11/06/1509948936651.PNG" 4 : "/images/2017/11/06/1509948936728.PNG"来渲染

<div class="pic" v-for="(img,key) in imagesData"> <VueImgInputer theme="light" size="small" placeholder="" accept="image/*" icon="true" noMask :capture="false" :imgSrc="img"> </VueImgInputer> </div>
,在页面上生成了4个VueImgInputer组件,每个都可以修改,预览。请问v-model怎么动态的绑定到组件中去呢?

通过相机回填图片不能触发onChange里面的回调函数?

<VueImgInputer v-model="picValue" theme="light" size="small" placeholder="" accept="image/*" icon="false" noMask :capture="false" :onChange=upLoadImg :imgSrc="this.avatar" > </VueImgInputer>

点击头像框,选择相册或者相机,回填后上传给后台。但是通过相机拍照不触发upLoadImg,在相册中选择图片却可以触发。
upLoadImg(file){ eventBus.$emit('showLoading'); this.picValue = file; console.log(this.picValue); let self = this; if (this.picValue.size) { global.compress(self.picValue, 0.1, function (err, data) { self.picValue = data; }); let postData = new FormData(); postData.append('action','update'); postData.append('nickname', self.userInfo.nickname); postData.append('avatar',self.picValue); global.requestData('post',url, (res)=>{ res = res.data; if(res && res.code === global.successNum){ console.log('上传成功') } }) } }

疑问

为什么刚开始使用还可以,过了一两天以后单击等选择图片弹出要隔四五秒,有时候达到七八秒?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.