Created
September 6, 2017 12:40
-
-
Save nikkanetiya/dada964a452f87c103ac2cd44ee667a4 to your computer and use it in GitHub Desktop.
NProgress bar with axios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'nprogress/nprogress.css' | |
import NProgress from 'nprogress' | |
import axios from 'axios' | |
const calculatePercentage = (loaded, total) => (Math.floor(loaded * 1.0) / total) | |
const setupUpdateProgress = () => { | |
axios.defaults.onDownloadProgress = e => { | |
const percentage = calculatePercentage(e.loaded, e.total) | |
NProgress.set(percentage) | |
} | |
} | |
const setupStopProgress = () => { | |
axios.interceptors.response.use(response => { | |
NProgress.done(true) | |
return response | |
}) | |
} | |
export function load(config) { | |
NProgress.configure(config) | |
setupUpdateProgress() | |
setupStopProgress() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, How to consume this code.? Thanks