How does axios get the request time

to make a loading progress bar, can axios, get the time it requested, or is there any easy way to implement


progress bars are generally fake.
during the request, the time is unknown, how to determine the percentage?
Axios.interceptors.request.use console.log (+ new Date ()) is the request time, isn't it? Put it in store . Get the end time in
Axios.interceptors.response.use .
but it's all over, and getting time doesn't seem to be of much use. What you need to do is to display the percentage during the request.

you can try this

vue-progressbar


axios can obtain the upload or download progress. Please see the two methods under the request configuration:

.
onUploadProgress: function (progressEvent) {
    // Do whatever you want with the native progress event
  },

  // `onDownloadProgress` allows handling of progress events for downloads
  onDownloadProgress: function (progressEvent) {
    // Do whatever you want with the native progress event
  },

I've tried and it's okay. The code I wrote before:

this.axios({
          method: 'POST',
          url: this.url,
          data: fmData,
          params: this.params,
          transformRequest: function(data) {
            return data
          },
          onUploadProgress: function(progressEvent) {
            vm.$nextTick(function() {
              if (progressEvent.total === 0) {
                vm.percentage = 0
              } else {
                vm.percentage = Math.round(
                  progressEvent.loaded * 100 / progressEvent.total
                )
              }
            })
          }
        })
Menu