progress-bar-4-axios

Slim progress bar (NProgress) for Web applications that use Axios library for HTTP requests

  • 所有者: rikmms/progress-bar-4-axios
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Axios Progress Bar

This module aims to provide a simple usage of a progress bar for the HTTP requests made by Web applications that use the library axios. It's high inspired in the module angular-loading-bar and uses the awesome nprogress module to display the loading bar in the Browser.

Attention: This module is not bound to any framework. You can use it in any Web application that uses axios.

Demo

demo


Installation

It's available through the NPM package:

npm install --save axios
npm install --save axios-progress-bar

Or via CDN:

<script src="https://cdn.rawgit.com/rikmms/progress-bar-4-axios/0a3acf92/dist/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

Usage

Invoke (only one time) the function: loadProgressBar(config, instance).

Nprogress Config

The config argument is the configuration object for the nprogress and is not required. Its properties can be seen here.

Custom Axios Instance

You can pass a Custom Axios Instance as a second argument if needed, the argument is not required. If you don't set the instance argument the default axios instance will be used.

Also, you need to import the CSS file (nprogress.css) that contains the customization of the progress bar.

Example in ES6 using the import statement

import { loadProgressBar } from 'axios-progress-bar'

loadProgressBar()
...

Don't forget to import the CSS in the HTML, or through JavaScript with some module bundler like webpack.

<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/rikmms/progress-bar-4-axios/0a3acf92/dist/nprogress.css" />
import 'axios-progress-bar/dist/nprogress.css'

Example using plain HTML and JavaScript in the Browser

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/rikmms/progress-bar-4-axios/0a3acf92/dist/nprogress.css" />
    </head>
    <body>
        ...
    </body>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.rawgit.com/rikmms/progress-bar-4-axios/0a3acf92/dist/index.js"></script>
    
    <script type="text/javascript">
        loadProgressBar()
        ...
    </script>
    
</html>

Tip

The CSS file contains the properties from the nprogress style. However, It's possible to override the properties or set new ones with a custom CSS.

In the next example, the custom CSS only changes the color of the progress bar and the spinner to red.

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/rikmms/progress-bar-4-axios/0a3acf92/dist/nprogress.css" />
        <style type="text/css">
            #nprogress .bar {
                background: red !important;
            }

            #nprogress .peg {
                box-shadow: 0 0 10px red, 0 0 5px red !important;
            }

            #nprogress .spinner-icon {
                border-top-color: red !important;
                border-left-color: red !important;
            }
        </style>
    </head>
    <body>
        ...
    </body>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.rawgit.com/rikmms/progress-bar-4-axios/0a3acf92/dist/index.js"></script>
    
    <script type="text/javascript">
        loadProgressBar()
        ...
    </script>
    
</html>

demo-red


Bugs/Requests

Write them in the repository issues.

Major changes

主要指标

概览
名称与所有者rikmms/progress-bar-4-axios
主编程语言HTML
编程语言JavaScript (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2017-09-05 14:13:43
推送于2022-06-09 08:59:40
最后一次提交2018-04-28 00:42:04
发布数4
最新版本名称1.1.0 (发布于 )
第一版名称0.1.2 (发布于 )
用户参与
星数248
关注者数5
派生数33
提交数46
已启用问题?
问题数16
打开的问题数9
拉请求数2
打开的拉请求数6
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?