Home JS special effects Other special effects vue.js image batch upload plug-in

vue.js image batch upload plug-in

vue.js image batch upload plug-in

The vue.js image batch upload plug-in is an image upload control based on the vue.js framework. It is suitable for mobile phone image upload code. It supports batch upload, drag-and-drop image upload, display of file number and size, etc.

js code

<script src="js/vue2.2.2.js"></script>
<script>
  //  import up from  './src/components/Hello'
  var app = new Vue({
    el: '#app',
    data () {
      return {
        imgList: [],
        size: 0
      }
    },
    methods: {
      fileClick(){
        document.getElementById('upload_file').click()
      },
      fileChange(el){
        if (!el.target.files[0].size) return;
        this.fileList(el.target.files);
        el.target.value = ''
      },
      fileList(files){
        for (let i = 0; i < files.length; i++) {
          this.fileAdd(files[i]);
        }
      },
      fileAdd(file){
        this.size = this.size + file.size;//总大小
        let reader = new FileReader();
        reader.vue = this;
        reader.readAsDataURL(file);
        reader.onload = function () {
          file.src = this.result;
          this.vue.imgList.push({
            file
          });
        }
      },
      fileDel(index){
        this.size = this.size - this.imgList[index].file.size;//总大小
        this.imgList.splice(index, 1);
      },
      bytesToSize(bytes){
        if (bytes === 0) return '0 B';
        let k = 1000, // or 1024
          sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
          i = Math.floor(Math.log(bytes) / Math.log(k));
        return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
      },
      dragenter(el){
        el.stopPropagation();
        el.preventDefault();
      },
      dragover(el){
        el.stopPropagation();
        el.preventDefault();
      },
      drop(el){
        el.stopPropagation();
        el.preventDefault();
        this.fileList(el.dataTransfer.files);
      }
    }
  })
</script>
Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

css special effects_html/css_WEB-ITnose css special effects_html/css_WEB-ITnose

24 Jun 2016

css special effects

Detailed usage tutorial of Yii2 component multi-image upload plug-in FileInput, yii2fileinput Detailed usage tutorial of Yii2 component multi-image upload plug-in FileInput, yii2fileinput

06 Jul 2016

Detailed usage tutorial for Yii2 component's multi-image upload plug-in FileInput, yii2fileinput. Detailed usage tutorial for Yii2 component multi-image upload plug-in FileInput. yii2fileinput will write an article about file upload in front of you, including the most basic yii2 file upload and asynchronous upload to

Detailed usage tutorial of Yii2 component multi-image upload plug-in FileInput_php example Detailed usage tutorial of Yii2 component multi-image upload plug-in FileInput_php example

06 Jul 2016

This article mainly introduces the relevant information on the detailed usage tutorial of the Yii2 component multi-image upload plug-in FileInput. It is very good and has reference value. Friends in need can refer to it.

HTML&css&j special effects_html/css_WEB-ITnose HTML&css&j special effects_html/css_WEB-ITnose

24 Jun 2016

HTML&css&j special effects

Detailed usage tutorial of Yii2 component multi-image upload plug-in FileInput, yii2fileinput_PHP tutorial Detailed usage tutorial of Yii2 component multi-image upload plug-in FileInput, yii2fileinput_PHP tutorial

12 Jul 2016

Detailed usage tutorial for Yii2 component's multi-image upload plug-in FileInput, yii2fileinput. Detailed usage tutorial for Yii2 component multi-image upload plug-in FileInput. yii2fileinput will write an article about file upload in front of you, including the most basic yii2 file upload and asynchronous upload to

61 web page special effects, very fashionable and with good visual effects_html/css_WEB-ITnose 61 web page special effects, very fashionable and with good visual effects_html/css_WEB-ITnose

24 Jun 2016

61 web page special effects that are very fashionable and have great visual effects

Animated loading effects implemented in pure css3_html/css_WEB-ITnose Animated loading effects implemented in pure css3_html/css_WEB-ITnose

24 Jun 2016

Animation loading special effects implemented in pure css3

jquery waterfall flow LightBox picture box special effects jquery waterfall flow LightBox picture box special effects

06 Jul 2016

jquery waterfall flow LightBox picture box special effects

Detailed use of the multi-image upload plug-in FileInput of the yii2 component, yii2fileinput Detailed use of the multi-image upload plug-in FileInput of the yii2 component, yii2fileinput

06 Jul 2016

Detailed use of the multi-image upload plug-in FileInput of the yii2 component, yii2fileinput. Detailed use of the multi-image upload plug-in FileInput of the yii2 component, yii2fileinput Author: Bailang Source: http://www.manks.top/yii2_multiply_images.html The copyright of this article belongs to the author, welcome to reprint,

See all articles See all articles

Hot Tools

jQuery+Html5 realizes beautiful confession animation code

jQuery+Html5 realizes beautiful confession animation code

jQuery+Html5 implements beautiful confession animation code, the animation effect is great, a must-have for programmers to confess!

Couple's romantic confession js special effects code

Couple's romantic confession js special effects code

JS special effects code for couples' romantic confession. Such special effects can be used on wedding photography websites or placed on personal websites. It is also a good special effect. PHP Chinese website recommends downloading!

Simple js love confession artifact

Simple js love confession artifact

Simple native js love confession artifact

Bunker's html5 particle animation expressive effects

Bunker's html5 particle animation expressive effects

Bunker's html5 particle animation expression special effects code, the animated special effects text can be changed in the code, you can make a page where you can customize text input, it should be very popular, this HTML5 special effect is very beautiful.

jQuery responsive background login interface template

jQuery responsive background login interface template

jQuery responsive backend login interface template html source code. The login page uses jquery to verify the form and determine whether the username and password meet the requirements. Usually the login page is a page that must be used on corporate websites or mall websites. Responsive backend pages, When the browser zooms in or out, the background will resize the image according to the browser! PHP Chinese website recommends downloading!