赞
踩
input 类型为type= file上传同一个文件不触发onchange事件的完整代码:
- document.querySelector('#file').setAttribute('type','text')
- this.timerTime = setTimeout(() => {
- document.querySelector('#file').setAttribute('type','file')
- }, 300);
-
记得在页面关闭的时候清除定时器
- destroyed() {
- clearTimeout(this.timerTime)
- }
上传成功之后设置input的类型为其他任何一个,然后再将类型设置为file就可以啦,我一开始使用的是将value置为空,但是对我没有效果,我的上传是这么写的,跟我写的一样的可以试一下
- chooseFile(event) {
- document.querySelector('#file').setAttribute('type','file')
- const files = event.target.childNodes[0].files[0];
- const formData = new FormData()
- formData.append('file',files)
- axios({
- url:'',
- method: 'post',
- data: formData,
- headers:{
- 'Content-Type':'multipart/form-data; boundary=----WebKitFormBoundaryg8qbK20fPSV2BxJB'
- }
- })
- .then(res=>{
- if (res.status == '200') {
- this.filesName.push({name:files.name,code:res.data.record.code})
- this.form.files.push(res.data.record.code);
-
- document.querySelector('#file').setAttribute('type','text')
- this.timerTime = setTimeout(() => {
- document.querySelector('#file').setAttribute('type','file')
- }, 300);
- }else {
- Taro.showToast({
- title: res.data.message,
- icon: "none",
- duration: 1000
- });
- }
- })
- },

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。