zoukankan      html  css  js  c++  java
  • [Vue-rx] Stream an API using RxJS into a Vue.js Template

    You can map remote data directly into your Vue.js templates using RxJS. This lesson uses axios (and the vue-axios library which exposes axios on components as this.$http) and wraps the remote call inside of an Observable to provide the data into the template

    Install:

    npm i --save axios vue-axios

    main.js:

    import 'buefy/lib/buefy.css'
    
    import Vue from 'vue'
    import App from './App.vue'
    
    import Rx from 'rxjs'
    import VueRx from 'vue-rx'
    
    import Buefy from 'buefy'
    
    import Axios from 'axios';
    import VueAxios from 'vue-axios'
    
    Vue.use(VueRx, Rx)
    Vue.use(Buefy)
    Vue.use(VueAxios, Axios)
    
    Vue.config.productionTip = false
    
    new Vue({
      render: h => h(App)
    }).$mount('#app')

    app.vue:

    <template>
      <section class="section">
        <h2>
          {{people$}}
        </h2>
      </section>
    </template>
    
    <script>
    import {  from } from 'rxjs';
    import { pluck } from 'rxjs/operators';
    
    export default {
      name: 'app',
      subscriptions() {
    
        const people$ = from(
          this.$http.get(
            "https://starwars.egghead.training/people/1"
          )
        ).pipe(
          pluck('data', 'name') // Get response.data.name
        )return {
          people$
        }
      }
    };
    </script>

  • 相关阅读:
    Hibernate 5.x 生成 SessionFactory 源码跟踪分析
    编译iftop
    Too many open files
    ffmpeg指定网卡
    abrt-hook-ccpp使用CPU太多
    ffplay播放时显示信息的意义
    Windows换行符和Linux换行符的替换
    directshow在WIN10下的一个BUG
    使用mirrordriver截屏
    mac xmind 激活
  • 原文地址:https://www.cnblogs.com/Answer1215/p/9325646.html
Copyright © 2011-2022 走看看