Vanthink-UED/vue-core-image-upload

Repository files navigation

npm

a vue plugin for image upload and crop ( Support πŸ“± IE10+)

ζŸ₯ηœ‹ζ–‡ζ‘£

English Document

if you use vue.js(<=2.0), you should go here.Or select 1.x.x version.

npm i vue-core-image-upload --save

Code Example (ES6)

<vue-core-image-upload
  :class="['btn', 'btn-primary']"
  :crop="false"
  @imageuploaded="imageuploaded"
  :data="data"
  :max-file-size="5242880"
  url="your server url" >
</vue-core-image-upload>
import VueCoreImageUpload  from 'vue-core-image-upload';

new Vue({
  el: '#app',
  components: {
    'vue-core-image-upload': VueCoreImageUpload
  },
  data: {
    src: 'http://img1.vued.vanthink.cn/vued0a233185b6027244f9d43e653227439a.png',
  },
  methods: {
     imageuploaded(res) {
      if (res.errcode == 0) {
        this.src = 'http://img1.vued.vanthink.cn/vued751d13a9cb5376b89cb6719e86f591f3.png';
      }
    }
  }
});

NUXT

import Vue from 'vue';
import VueCoreImageUpload from 'vue-core-image-upload/dist/ssr';

Vue.use( VueCoreImageUpload );

plugins: [
  { src: '~plugins/vue-core-image-upload.js', ssr: false }
]

Demo

PropsData TypeExampleDetails
urlString'/crop.php'Your server api
textString'Upload Image'The text of your uploading button
inputOfFileString      'file'Yout input[file] name
extensionsString'png,jpg,gif'Limit the image type
cropBoolean'server'Crop image option
cropRatioString'1:1'The cropped image shape
cropBtnObject{ok:'Save','cancel':'Give Up'}The Text of cropping button text
maxFileSizeNumber10485760(10M)Limit the size of the file
maxFileSizeNumber10485760(10M)Limit the size of the file
multipleSizeNumber5Limit the count of the file
maxWidthNumber150The maximum width of cropped image
maxheightNumber150ι™εˆΆε›Ύη‰‡ηš„ζœ€ε€§ι«˜εΊ¦
inputAcceptstring'image/*' / 'image/jpg,image/jpeg,image/png'the input[file] accept
compressNumber50Set the quality of compressed image
isXhrBooleantrueIF cancel ajax uploading
headersObject{auth: xxxxx}Set customed header when ajax uploading
dataObject{auth: xxxxx}Set customed data when ajax posting server

Your contributions and suggestions are welcome πŸ˜„πŸ˜„πŸ˜„πŸ’πŸ’πŸ’.