vue-use-async
TypeScript icon, indicating that this package has built-in type declarations

1.9.8 • Public • Published

Xhr helpers to use in VueJS 3 projects

Navigation

Installation

npm install vue-use-async

Usage

Xhr Class

import { Xhr } from 'vue-use-async';

new Xhr().get({ url: '/' });

useXhr

import { useXhr } from 'vue-use-async';

export default function () {
  const { get } = useXhr({ token });

  const { 
    data, 
    isPending,
    promise,
  } = get({ url: '/', cacheDuration: 200 });

  // ...
}

E.g; In setup, a computed bearer token can be used. Each query has data bind to be used directly in a template. A cache can be specified, therefore during this time another query with same parameters will be directly resolved.

useAsync

Similar to useXhr can resolve a function when computed parameters changed. if condition is used, the function will wait true before being applied.

import { useAsync } from 'vue-use-async';

export default function () {
  const func = () => Promise.resolve('ok');

  const { data } = useAsync(func, [params, condition]);

  // ...
}

useMutation

Create a mutate function to be called with parameters.

import { useMutate } from 'vue-use-async';
const {
  mutate,
  onEnd,
  onError,
} = useMutation(update);

mutate(p1, p2, p3);

// ...

useResult

useXhr and useAsyc return data. By default, it will be null. Thanks to useResult it's possible to initialize it.

import { useAsync, useResult } from 'vue-use-async';

const { data } = useAsync(getProducts);

const products = useResult(data, []);

// ...

useSpinner

Useful to bind the isPending to a spinner icon with a minimum duration.

import { useAsync, useSpinner } from 'vue-use-async';

export default function () {
  const func = () => Promise.resolve('ok');

  const { data, isPending } = useAsync(func, [params, condition]);

  const isPendingSpinner = useSpinner(isPending);

  // ...
}

error handler

It's possible to capture rejected promise with errorCaptured

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.9.822latest

Version History

VersionDownloads (Last 7 Days)Published
1.9.822
1.9.71
1.9.60
1.9.50
1.9.41
1.9.31
1.9.20
1.9.11
1.9.00
1.9.0-beta.60
1.9.0-beta.50
1.9.0-beta.40
1.9.0-beta.30
1.9.0-beta.20
1.8.80
1.8.70
1.8.60
1.8.50
1.8.40
1.8.30
1.8.10
1.8.01
1.7.50
1.7.41
1.7.30
1.7.20
1.7.10
1.7.00
1.6.120
1.6.110
1.6.100
1.6.90
1.6.80
1.6.70
1.6.60
1.6.50
1.6.40
1.6.30
1.6.21
1.6.10
1.6.00
1.5.00
1.4.80
1.4.60
1.4.50
1.4.41
1.4.31
1.4.20
1.4.10
1.4.00
1.3.11
1.3.00
1.2.20
1.2.00
1.1.280
1.1.270
1.1.260
1.1.250
1.1.240
1.1.231
1.1.220
1.1.210
1.1.200
1.1.190
1.1.180
1.1.170
1.1.161
1.1.150
1.1.141
1.1.131
1.1.121
1.1.110
1.1.100
1.1.90
1.1.80
1.1.70
1.1.60
1.1.40
1.1.30
1.1.20
1.1.10
1.1.00
1.0.41
1.0.20
0.4.250
1.0.10
1.0.00
0.4.241
0.4.231
0.4.220
0.4.211
0.4.201
0.4.191
0.4.181
0.4.171
0.4.160
0.4.150
0.4.140
0.4.132
0.4.120
0.4.110
0.4.90
0.4.80
0.4.71
0.4.60
0.4.51
0.4.40
0.4.30
0.4.20
0.4.11
0.4.00
0.3.210
0.3.200
0.3.190
0.3.180
0.3.170
0.3.160
0.3.150
0.3.140
0.3.130
0.3.120
0.3.110
0.3.100
0.3.90
0.3.80
0.3.70
0.3.60
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10
0.3.00
0.2.130
0.2.120
0.2.111
0.2.101
0.2.90
0.2.80
0.2.70
0.2.60
0.2.50
0.2.40
0.2.30
0.2.20
0.2.10
0.2.01
0.1.10
0.1.00
0.0.50
0.0.40
0.0.30
0.0.20
0.0.10
0.0.1-beta.10

Package Sidebar

Install

npm i vue-use-async

Weekly Downloads

53

Version

1.9.8

License

MIT

Unpacked Size

49.5 kB

Total Files

17

Last publish

Collaborators

  • tcy