Skip to content

useSubscription

Category
Export Size
144 B
Package
@vueuse/rxjs
Last Changed
3 years ago

使用 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

SourceDocs

贡献者

Anthony Fu
丶远方
Anthony Fu
Curt Grimes
katsuya_U
Michel Betancourt

变更日志

No recent changes

Released under the MIT License.