[Vuejs]-Vue Get uploaded files url

0👍

you can use :before-upload attribute of el-upload. please take look of changed code.

<div id="app">
<el-upload action="https://jsonplaceholder.typicode.com/posts/" **:before-upload="checkType"** list-type="picture-card" :on-preview="handlePictureCardPreview" :on-remove="handleRemove">
<i class="el-icon-plus"></i>
</el-upload>
<el-dialog :visible.sync="dialogVisible">
<embed width="100%" :src="dialogImageUrl">
</el-dialog>

<p>file type: "{{ checkType() }}"</p>
</div>

var Main = {
data() {
  return {
    dialogImageUrl: '',
    dialogVisible: false
  };
},
methods: {
  handleRemove(file, fileList) {
    console.log(file, fileList);
  },
  handlePictureCardPreview(file) {
    this.dialogImageUrl = file.url;
    this.dialogVisible = true;
  },
  **checkType(file){**
    console.log(file.type);
    // do your action here based on file.type
     var filename =  this.dialogImageUrl;  
     return filename.split('.').pop(); 

  }
 }
}

Leave a comment