0

我正在使用当前版本的Laravel& Inertia.js。我也在使用IntertiaProgress并希望在文件上传期间使用它axios

文件全部上传正常,但控制台显示:

app.js:33316 Uncaught (in promise) TypeError: Cannot read property 'defaultPrevented' of undefined

追溯它的来源,它指向这里InertiaProgress

 start(event) {
    Promise.resolve().then(() => {
      if (event.defaultPrevented) {
        return
      }

      this.inProgress++
      clearTimeout(this.timeout)
      this.timeout = setTimeout(() => {
        Nprogress.set(0)
        Nprogress.start()
      }, this.delay)
    })
  },

如果console.log(event)我得到undefined

我的upload()方法:

upload(files) {
    let url = this.$route('library.upload');
    this.$root.showLoading = true;

    const uploadConfig = {
        timeout: 10000,
        onUploadProgress: function(progressEvent) {
            let percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
            InertiaProgress.progress(percentCompleted)
        }
    }

    InertiaProgress.start()

    axios.post(url, {
        files,
    },
        uploadConfig
    ).then(res => {
        let files = res.data.files
        if (files.length) {
            this.filesList = cloneDeep(files)
        }

        this.newFiles = []

        InertiaProgress.finish()
        this.$root.showLoading = false
    }).catch(err => {
        console.log(err)

        InertiaProgress.finish()
        this.$root.showLoading = false
    })
},

任何帮助表示赞赏

4

0 回答 0