# vue-loading-for-ajax

> vue-loading-for-ajax

Latest version **0.1.2** (published 2018-10-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install vue-loading-for-ajax
pnpm add vue-loading-for-ajax
yarn add vue-loading-for-ajax
bun add vue-loading-for-ajax
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2018-10-26 |
| First published | 2018-10-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 312.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ss707494@163.com |
| Maintainers | ss707494 |
| Keywords | vue, loading, ajax |

## Links

- npm: https://www.npmjs.com/package/vue-loading-for-ajax
- Repository: https://github.com/ss707494/vueLoadingForAjax
- Homepage: https://github.com/ss707494/vueLoadingForAjax#readme
- Issues: https://github.com/ss707494/vueLoadingForAjax/issues
- npm.io page: https://npm.io/package/vue-loading-for-ajax

## Recent versions

- 0.1.2 (latest) — 2018-10-26
- 0.1.1 — 2018-10-26
- 0.0.7 — 2018-10-26
- 0.0.6 — 2018-10-26

## README

# vue-loading-for-ajax
在vue中添加全局状态，监听请求发送及完成情况，便于在组件中添加loading或disabled状态

[demo](https://ss707494.github.io/vueLoadingForAjax/) 需翻墙

## Usage

```bash
npm i vue-loading-for-ajax --save
```
在vue中加入
```javascript
import Vur from 'vue'
import vueLoadingForAjax from 'vue-loading-for-ajax'
Vue.use(vueLoadingForAjax)
```
在请求中监听
```javascript
import vueLoadingForAjax from 'vue-loading-for-ajax'
// in ajax request (mabey in global)
let config
function beforeAjax() {
  config = vueLoadingForAjax.startAjax({url: '...'}) // this config has a id , it will use when stop 
}
function afterAjax() {
  vueLoadingForAjax.stopAjax(config)
}
```
在axios可以不用添加监听事件,插件中已经添加如下代码
```javascript
    axios.interceptors.request.use(config => {
      return loadingData.startAjax(config)
    })
    axios.interceptors.response.use(response => {
      loadingData.stopAjax(response.config)
      return response
    })
```
在vue组件中,每一实例都有一个isLoadingForUrl方法,用来判断该url是否正在发送请求
```vue
  isLoadingForUrl('getData') 
  // 在ele ui中button组件可以这样使用
  <el-button :loading="isLoadingForUrl('getData')">提交</el-button>
```

#### isLoadingForUrl 
##### 参数
#####url:判断该url是否在请求中
可以传字符串'getListData'（或部分匹配'ListData'），若是多个可以传数组或逗号(,)拼接

---
_Source: https://npm.io/package/vue-loading-for-ajax · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
