Skip to content

Commit c9a7e68

Browse files
committed
chore: update README
1 parent c7e0a5f commit c9a7e68

File tree

2 files changed

+50
-52
lines changed

2 files changed

+50
-52
lines changed

README.md

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ English | [中文](./README-zh_TW.md)
66

77
## Introduction
88

9-
Vue composition API for automatic data fetching. With `conditions` as the core. Easily control and sync to URL query string by `conditions`
9+
Data fetching with Vue Composition API. Power of `conditions` to easily control and sync to the URL query string.
1010
> requires Node.js 12.0.0 or higher.
1111
1212
## Features
1313

14-
✔ Automatically fetch data whenever `conditions` changes<br>
15-
`null` `undefined` `[]` `''` will be automatically filtered out before sending the request<br>
16-
Refreshing the page will automatically initialize `conditions` according to the query string of the URL, and will automatically correspond to the type ( string, number, array, date )<br>
17-
✔ Whenever `conditions` changes, the URL query string will be automatically synchronized, and the previous page and next page will work normally<br>
18-
✔ Avoid `race condition`, ensure requests are first in, first out, and can also avoid repeated requests<br>
19-
Do Dependent Request before updating `data`<br/>
20-
✔ Easily handle paging needs, simply customize your own paging logic<br/>
21-
✔ Automatically re-request data when web page is refocused or network disconnection resumes<br/>
22-
✔ Support polling, the polling period can be adjusted dynamically<br/>
23-
✔ The caching mechanism allows data to be rendered faster without waiting for loading animations<br/>
24-
✔ No need to wait for the return result, you can manually change `data` to make the user experience better<br/>
25-
✔ TypeScript support. <br/>
26-
✔ Works for Vue 2 & 3 by the power of [vue-demi](https://github.com/vueuse/vue-demi)
14+
✔ Automatically fetch data whenever `conditions` change.<br>
15+
Automatically filter out `null`, `undefined`, `[]`, and `''` before sending the request.<br>
16+
Refresh the page to automatically initialize `conditions` according to the query string of the URL, and correspond to the type (string, number, array, date).<br>
17+
✔ Whenever `conditions` change, the URL query string will be automatically synchronized, and the previous page and next page will work normally.<br>
18+
✔ Avoid race conditions, ensure requests are first in, first out, and can also avoid repeated requests.<br>
19+
Perform dependent requests before updating data.<br/>
20+
✔ Easily handle paging needs by customizing your own paging logic.<br/>
21+
✔ Automatically refetch data when the web page is refocused or network disconnection resumes.<br/>
22+
✔ Support polling, with the polling period adjustable dynamically.<br/>
23+
✔ The caching mechanism allows `data` to be rendered faster without waiting for loading animations.<br/>
24+
✔ No need to wait for the return result; you can manually change `data` to improve the user experience.<br/>
25+
✔ TypeScript support.<br/>
26+
✔ Works for Vue 2 & 3 through the power of [vue-demi](https://github.com/vueuse/vue-demi).
2727

2828
<img src=".github/vue-conditions-watcher.gif"/>
2929

@@ -93,49 +93,47 @@ https://unpkg.com/vue-condition-watcher/dist/index.js
9393

9494
### Quick Start
9595

96-
This is a simple example for `vue-next` and `vue-router-next`
96+
You can start by creating a fetcher function using the native `fetch` or libraries like `Axios`. Then, import the `useConditionWatcher` function and start using it. Here's an example:
9797

98-
First you need to create a fetcher function, use the native `fetch` or libs like Axios. Then import `useConditionWatcher` and start using it.
98+
```html
99+
<script setup>
100+
import axios from 'axios'
101+
import { useRouter } from 'vue-router'
102+
import { useConditionWatcher } from 'vue-condition-watcher'
99103
100-
```javascript
101-
createApp({
102-
template: `
103-
<div class="filter">
104-
<input v-model="conditions.name">
105-
<button @click="execute">Refetch</button>
106-
</div>
107-
<div class="container">
108-
{{ !loading ? data : 'Loading...' }}
109-
</div>
110-
<div v-if="error">{{ error }}</div>
111-
`,
112-
setup() {
113-
const fetcher = params => axios.get('/user/', {params})
114-
const router = useRouter()
115-
116-
const { conditions, data, loading, execute, error } = useConditionWatcher(
117-
{
118-
fetcher,
119-
conditions: {
120-
name: ''
121-
},
122-
history: {
123-
sync: router
124-
}
125-
}
126-
)
127-
return { conditions, data, loading, execute, error }
128-
},
129-
})
130-
.use(router)
131-
.mount(document.createElement('div'))
104+
const fetcher = params => axios.get('/user/', {params})
105+
const router = useRouter()
106+
107+
const { conditions, data, loading, execute, error } = useConditionWatcher(
108+
{
109+
fetcher,
110+
conditions: {
111+
name: ''
112+
},
113+
history: {
114+
sync: router
115+
}
116+
}
117+
)
118+
</script>
119+
120+
<template>
121+
<div class="filter">
122+
<input v-model="conditions.name">
123+
<button @click="execute">Refetch</button>
124+
</div>
125+
<div class="container">
126+
{{ !loading ? data : 'Loading...' }}
127+
</div>
128+
<div v-if="error">{{ error }}</div>
129+
</template>
132130
```
133131

134-
You can use the value of `data`, `error`, and `loading` to determine the current state of the request.
132+
The `useConditionWatcher` function returns an object with three properties: `data`, `error`, and `loading`. You can use these values to determine the current state of the request.
135133

136-
When the `conditions.name` value changes, will fire the `lifecycle` to fetching data again.
134+
When the value of `conditions.name` changes, `useConditionWatcher` will automatically refetch the data.
137135

138-
Use `config.history` of sync to `sync: router`. Will store the conditions within the URL query string every time conditions change.
136+
You can use the `config.history` option to sync the conditions object with the router. This will store the conditions object within the URL query string every time it changes.
139137

140138
### Basic Usage
141139

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-condition-watcher",
33
"version": "2.0.0-beta.3",
4-
"description": "Vue composition API for automatic data fetching. With conditions as the core. Easily control and sync to URL query string by conditions",
4+
"description": "Data fetching with Vue Composition API. Power of conditions to easily control and sync to the URL query string.",
55
"main": "./core/dist/index.js",
66
"module": "./core/dist/index.esm.js",
77
"types": "./core/dist/core/index.d.ts",

0 commit comments

Comments
 (0)