依赖刷新
watchSource 是 useRequest 提供的语法糖,用于替代 Vue3 中常见的 watch + 手动触发请求的写法。 它让你可以在依赖项变化时自动刷新请求,不再需要手动调用 refresh()。
手动收集依赖
在下面的案例中,切换 radio 的时候会自动刷新请求。
自动收集依赖
设置 watchSource 为 true 时,useRequest 会自动收集 server 中的响应式数据源,并在其变化时自动刷新请求。
我将上面的案例改一下,将 watchSource 设置为 true,会自动收集 server 中的 type依赖项,并在其变化时自动刷新请求。
API
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| watchSource | true | WatchSource | WatchSource[] | 500 |
|
| watchDeep | boolean | false | 是否深度观察,用法与 vue watch 中的 deep一致 |
