Vue 图片上传组件

阅读 6667
收藏 0

Mobile-friendly picture file input Vue.js component with image preview, drag and drop, EXIF orientation, and more.

Picture Input Demo



npm install --save vue-picture-input


  <div class="hello">    
    <picture-input ref="pictureInput" @change="onChange" width="600" height="600" margin="16" accept="image/jpeg,image/png" size="10" buttonClass="btn"></picture-input>
import PictureInput from 'vue-picture-input'

export default {
  name: 'app',
  data () {
    return {
  components: {
  methods: {
    onChange () {
      console.log('New picture selected!')
      if (this.$refs.pictureInput.image) {
        console.log('Picture loaded.')
      } else {
        console.log('FileReader API not supported: use the <form>, Luke!')

Example project

You can find an example project here:…


  • width, height: (pixels, optional) the maximum width and height of the preview container. The picture will be resized and centered to cover this area. If not specified, the preview container will expand to full width, 1:1 square ratio.
  • margin: (pixels, optional) the margin around the preview container. Default value: 0.
  • accept: (media type, optional) the accepted image type(s), e.g. image/jpeg, image/gif, etc. Default value: 'image/*'.
  • size: (MB, optional) the maximum accepted file size in megabytes.
  • id, name: (string, optional) the id and name attributes of the HTML input element.
  • buttonClass: (string, optional) the class which will be applied to the 'Change Photo' button.


  • change: emitted on (successful) picture change. If you need to access the underlying image from the parent component, add a ref attribute to picture-input (see the example above).


  • Add support for multiple files (?)
  • Demo GitHub pages


All contributions are welcome.