zoukankan      html  css  js  c++  java
  • [Vue-rx] Watch Vue.js v-models as Observable with $watchAsObservable and RxJS

    You most likely already have data or properties in your template which are controlled by third-party components or updated using data binding. You can still use this data as stream by leveraging vue-rx's $watchAsObservable then chaining RxJS operators onto it as a new stream.

    For example in our Vue page:

    export default {
      name: 'app',
      data() {
        return {
          activeTab: 0
        }
      },
     ...
    }

    We have a 'activeTab', which bind to template:

      <b-tabs v-model="activeTab">
        <b-tab-item label="Luke"></b-tab-item>
        <b-tab-item label="Darth"></b-tab-item>
        <b-tab-item label="Leia"></b-tab-item>
      </b-tabs>

    We can use '$watchAsObservable' to convert the value to Observable value:

      subscriptions() {
    
        const activeTab$ = this.$watchAsObservable('activeTab', {immediate: true}).pipe(pluck('newValue'))
    
        return {activeTab$ }
    
    }
  • 相关阅读:
    NSThread 多线程 三种方式
    CABasicAnimation 核心动画
    图片圆角属性
    GCD
    IOS 推送
    IOS 截图
    UIImage 截图
    UIImageView 动画
    AFN 判断网络状态
    Template 模式
  • 原文地址:https://www.cnblogs.com/Answer1215/p/9332323.html
Copyright © 2011-2022 走看看