如何解决在Safari中调用Axios上传进度回调,但在Chrome中从不调用
我正在尝试在vuejs,turbolinks和rails中使用axios实现上传进度栏。 因此我添加了以下代码,该代码可在Safari中使用,但不能在Chrome中完全使用。
// initialize
import VueAxios from 'vue-axios';
import axios from 'axios';
Vue.use(VueAxios,axios);
document.addEventListener('turbolinks:load',() => {
axios.defaults.headers.common['X-CSRF-Token'] = document.querySelector(`meta[name="csrf-token"]`).getAttribute('content');
});
// form data prepare
const formData = new FormData();
formData.append('create_request[attachments_attributes][0][image]',fileElement.files[0]);
formData.append('create_request[attachments_attributes][0][note]','lorem ipsum');
// configuration
const config = {
onUploadProgress: (e) => {
console.log('uploading ...',e.loaded,e.total);
},onDownloadProgress: (e) => {
console.log('downloading ...');
}
}
// form submit
try {
await this.$http.put("/submit.json",formData,config);
} catch (err) {
...
}
“ onDownloadProgress”始终针对Safari和Chrome进行调用。 但是“ onUploadProgress ”仅在Safari中可用,从不在 Chrome 中不可用。 请让我知道原因。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。