Vue input file 圖片上傳

<input type="file" @change="addImg" ref="inputer" multiple />

addImg(e) {

      let inputDOM = this.$refs.inputer;

      this.fil = inputDOM.files;

      console.log(this.fil)

      for (let i = 0; i < this.fil.length; i++) {

        let size = Math.floor(this.fil[i].size / 1024);

        if (size > 5 * 1024 * 1024) {

          alert("請選擇5M以內的圖片!");

          return false;

        }

        this.imgLen++;

        this.$set(

          this.imgs,

          this.fil[i].name + "?" + new Date().getTime() + i,

          this.fil[i]

        );

      }

    },

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章