当前位置:   article > 正文

input文件上传第二次上传失败_input上传文件 第二次上传失效

input上传文件 第二次上传失效

input 类型为type= file上传同一个文件不触发onchange事件的完整代码:

  1. document.querySelector('#file').setAttribute('type','text')
  2. this.timerTime = setTimeout(() => {
  3. document.querySelector('#file').setAttribute('type','file')
  4. }, 300);

记得在页面关闭的时候清除定时器

  1. destroyed() {
  2. clearTimeout(this.timerTime)
  3. }

 上传成功之后设置input的类型为其他任何一个,然后再将类型设置为file就可以啦,我一开始使用的是将value置为空,但是对我没有效果,我的上传是这么写的,跟我写的一样的可以试一下

  1. chooseFile(event) {
  2. document.querySelector('#file').setAttribute('type','file')
  3. const files = event.target.childNodes[0].files[0];
  4. const formData = new FormData()
  5. formData.append('file',files)
  6. axios({
  7. url:'',
  8. method: 'post',
  9. data: formData,
  10. headers:{
  11. 'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryg8qbK20fPSV2BxJB'
  12. }
  13. })
  14. .then(res=>{
  15. if (res.status == '200') {
  16. this.filesName.push({name:files.name,code:res.data.record.code})
  17. this.form.files.push(res.data.record.code);
  18. document.querySelector('#file').setAttribute('type','text')
  19. this.timerTime = setTimeout(() => {
  20. document.querySelector('#file').setAttribute('type','file')
  21. }, 300);
  22. }else {
  23. Taro.showToast({
  24. title: res.data.message,
  25. icon: "none",
  26. duration: 1000
  27. });
  28. }
  29. })
  30. },

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/181535
推荐阅读
相关标签
  

闽ICP备14008679号