useSubscription
使用 RxJS Subscription
,无需担心取消订阅或创建内存泄漏。 Available in the @vueuse/rxjs add-on.
用法
ts
import { useSubscription } from '@vueuse/rxjs'
import { interval } from 'rxjs'
const count = ref(0)
// 在组件卸载前调用 unsubscribe 方法
useSubscription(
interval(1000)
.subscribe(() => {
count.value++
console.log(count)
}),
)
类型声明
typescript
export declare function useSubscription(subscription: Unsubscribable): void
Source
贡献者
Anthony Fu
丶远方
Anthony Fu
Curt Grimes
katsuya_U
Michel Betancourt