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>

[Vue-rx] Stream an API using RxJS into a Vue.js Template的更多相关文章

  1. Vue 3.0 Composition API - 中文翻译

    Composition API 发布转载请附原文链接 https://www.cnblogs.com/zgh-blog/articles/composition_api.html 这两天初步了解了下 ...

  2. vue中百度地图API的调用

    1.使用百度地图api需要使用jsonp,来获取百度api的返回,因为vue不自带jsonp所以需要下载 安装jsonp npm i vue-jsonp -S 引入jsop import Vue fr ...

  3. Vue 3.x Composition API

    Vue 3.x Composition API setup 调用时机 创建组件实例,然后初始化 props ,紧接着就调用setup 函数; 从生命周期钩子的视角来看,它会在 beforeCreate ...

  4. Vue 爬坑之路(十一)—— 基于 Nuxt.js 实现服务端渲染(SSR)

    直接使用 Vue 构建前端单页面应用,页面源码时只有简单的几行 html,这并不利于网站的 SEO,这时候就需要服务端渲染 2016 年 10 月 25 日,zeit.co 背后的团队对外发布了一个 ...

  5. 从零开始系列之vue全家桶(2)安装调试插件vue Devtools

    小白安装前提是会用git,会从github上找东西. 第一步: 我们可以先从github上找到vue-devtools的项目,下载到本地.下载vue-devtools链接. 克隆方法:git clon ...

  6. Vue学习——使用vue-cli搭建一个简单的本地vue项目

    前提 安装好node.js.npm.vue-cli.为什么要先安装这些,建议查看https://www.cnblogs.com/jixue/p/10673875.html,这个对于vue-cli理解很 ...

  7. 以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明

    以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明 为了让你的Ðapp运行上以太坊,一种选择是使用web3.js library提供的web3.对象.底层实 ...

  8. [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

    转载自:https://segmentfault.com/a/1190000006435886 解决办法:添加package.config.js配置文件中,添加本文章的红色部分代码 import vu ...

  9. atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js

    atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js 1. 两个方法:: bat vs mysqldump(推荐)  vs   lang  ...

随机推荐

  1. Hadoop的数据采集框架

    问题导读: Hadoop数据采集框架都有哪些? Hadoop数据采集框架异同及适用场景? Hadoop提供了一个高度容错的分布式存储系统,帮助我们实现集中式的数据分析和数据共享.在日常应用中我们比如要 ...

  2. hihocoder offer收割编程练习赛13 D 骑士游历

    思路: 矩阵快速幂. 实现: #include <iostream> #include <cstdio> #include <vector> using names ...

  3. opencv3+python+pycharm报错问题(cmd命令正常)

    2018-03-0223:58:59 首先在你已成功安装python的情况下运行cmd命令,下载安装opencv插件 如果在命令行可以使用 import cv2 但是在IDE上面只输入import c ...

  4. arduino相关资料和网站

    2018-02-0212:59:12 昨天晚上在论坛里看了大半夜,找到了很多有意思的项目,总结一下! http://www.51hei.com/bbs/dpj-105654-1.html   ---贪 ...

  5. TOP5_3:定制简单的进度条

    结构: Activity: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xm ...

  6. UVM基础之------uvm phases机制

    代码的书写顺序会影响代码的实现,在不同的时间做不同的事情,这是UVM phase的设计哲学,UVM phase提供了一个通用的TB phase 解决方案.支持显示的隐式的同步方案,运行时刻的线程控制和 ...

  7. CentOS上oracle 11g R2数据库安装折腾记

    1.虚拟机上centos镜像的获取.这里推荐网易镜像站中的CentOS7版本(其他开源镜像站亦可).这里给出链接: http://mirrors.163.com/centos/7.3.1611/iso ...

  8. jmeter接口测试小结

    摘自:http://www.cnblogs.com/houzhizhe/p/6839736.html JMeter做http接口压力测试 测前准备 用JMeter做接口的压测非常方便,在压测之前我们需 ...

  9. vi 命令学习(二)

    [选中文本(可视模式)] v 可视模式 从光标位置开始按正常模式选择文本 V 可视行模式 选中光标经过的完整行 ctrl + v 可视块模式 垂直方向选中文本 [ 撤销和恢复撤销] u undo 撤销 ...

  10. python3 的range

    1. range(3):从0到2: 2. range(3,10,2):从3到10,隔一个数显示一个: 3.list(range(3,10,-2):结果为空: 4. S[::2] : 同隔一个数显示一个 ...