Vue IVIEW Upload Component Manual Upload Different

Based on the UI component Vue library has now a lot, especially in the mobile terminal. Now one more iView.

iView mainly serving the PC interface in the back-office operations, is a high-quality open-source UI component library, the first on the address:

https://github.com/iview/iview

official website is:

https://www.iviewui.com/

characteristics

  • single file Vue component-based development model
  • based on npm + webpack + babel development, support ES2015
  • high-quality, feature-rich
  • -friendly API, freedom and flexibility to use the space
  • detailed, friendly document, unavoidably

a recent issue

the functional requirements of point

    met at a back-end system with functions summary
  • Upload select the file to determine the file format
  • to save the file you want to upload, display the file name
  • provides delete file function (not before uploading)
  • upload files

upload component iView provided

     
Upload file: {{item .name}} X

parameters used in the API / method

  • multiple: whether to support multi-select files by default false
  • before-upload: Upload the event hook before the file, if you return false or promise, stop automatically upload
  • show-upload-list: Whether the list of uploaded file list is default to true
  • On-Success: After the file is successfully successfully, returns the res (the information returned by the interface), File (Upload file), FileList (Upload file list)
  • Action: File upload address

Upload selection file judgment file format save file

After the file will call the method, what is done inside has the judgment file type to meet the needs, if satisfied In the file list that needs to be uploaded, here we need to define a keyid, should be displayed, delete the function, if no unique ID does not know the

here if the file is allowed to upload But what is your heart, this hook will call the selected as a group of hooks before the file event, so it is not possible, but the multi-file selection will only generate a keyid

  HandleUpload (file) {// Upload Event Hook before Upload File // Select File Here, Decision File Type Save File Custom A KeyID Value Convenient Back Operation Let Keyid = Math.random (). Tostring (). Substr (2 ); file ['keyid'] = keyid; // save files to the total display file data. .file.push (file); // Save File to the file number required to upload this.uploadFile.push (file) / / Return Falsa Stop Auto Upload We need to manually upload returnafse;}  

Delete function

delectFile (keyid) {// delete file // delete the total display file Current file this.file = this.file.filter (item => {return item.name! = Name}) // Remove the current file in the file data this.uploadFile = this.uploadFile.filter (item => { Return Item.KeyID! = keyid}}
   
Upload file

UPLOAD () {// Upload file for (let i = 0; i

Here if it is a multi-file, you need to loop up one by one, if you upload more A component will report an error, only to upload a file, I hope that IVIEW will support multiple uploads, this upload me starts can’t find it, I don’t know how to manually get it, how to send it, I will find it for a long time, in There is also an example in the official document, there is an example of manually uploading but:
  There is no fact that the operation is only simulated, the upload method is in the source code Found < this.uploadFile.length; i++) {
  let item = this.file[i]
  this.$refs.upload.post(item);
 }
}, 
After the upload is successful

should be our upload file function and the data submitted to the entire page is separated, so it is necessary to verify whether the file is selected or not. In the uploading successful event, let’s return the data we passed to the data to be cleared to the data in the file. You can only determine if the data to be uploaded is empty.

vue iView 上传组件之手动上传功能 file upload Tune returns three parameters

The address of the upload result is successful and failed to upload the address

File this uploaded file

    UPLOADSUCCESS (RES, FILE) {// File upload callback Upload successfully removed confested file console.log (response) Console.log (file)},

  • Here is a small problem to be uploaded, it is loop call upload. If multiple files are uploaded here, there will be multiple callback results can’t successfully a file prompts the user, so you need to handle it. Customize a number of callbacks every time the callback Self-processing, when the value is equal to the length of the LENGTH to be uploaded, it is prompted to upload the result
Complete code github address https://github.com/bailin240/AarticlePload / 103 ]
 Summary   
The above is the manual upload function of the Vue IVIEW uploading component described above. I hope that everyone can help, if you have any questions, please give I leave a message, the small package will reply to everyone in time. Thank you very much for your support of Tumi Cloud Website!
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment