[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>
[Vue-rx] Stream an API using RxJS into a Vue.js Template的更多相关文章
- Vue 3.0 Composition API - 中文翻译
Composition API 发布转载请附原文链接 https://www.cnblogs.com/zgh-blog/articles/composition_api.html 这两天初步了解了下 ...
- vue中百度地图API的调用
1.使用百度地图api需要使用jsonp,来获取百度api的返回,因为vue不自带jsonp所以需要下载 安装jsonp npm i vue-jsonp -S 引入jsop import Vue fr ...
- Vue 3.x Composition API
Vue 3.x Composition API setup 调用时机 创建组件实例,然后初始化 props ,紧接着就调用setup 函数; 从生命周期钩子的视角来看,它会在 beforeCreate ...
- Vue 爬坑之路(十一)—— 基于 Nuxt.js 实现服务端渲染(SSR)
直接使用 Vue 构建前端单页面应用,页面源码时只有简单的几行 html,这并不利于网站的 SEO,这时候就需要服务端渲染 2016 年 10 月 25 日,zeit.co 背后的团队对外发布了一个 ...
- 从零开始系列之vue全家桶(2)安装调试插件vue Devtools
小白安装前提是会用git,会从github上找东西. 第一步: 我们可以先从github上找到vue-devtools的项目,下载到本地.下载vue-devtools链接. 克隆方法:git clon ...
- Vue学习——使用vue-cli搭建一个简单的本地vue项目
前提 安装好node.js.npm.vue-cli.为什么要先安装这些,建议查看https://www.cnblogs.com/jixue/p/10673875.html,这个对于vue-cli理解很 ...
- 以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明
以太坊智能合约开发,Web3.js API 中文文档 ethereum web3.js入门说明 为了让你的Ðapp运行上以太坊,一种选择是使用web3.js library提供的web3.对象.底层实 ...
- [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 ...
- atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js
atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js 1. 两个方法:: bat vs mysqldump(推荐) vs lang ...
随机推荐
- opencv 检测图片中圆形物体(解决乱线问题)
2018-03-0418:03:12 整体代码如下: def detect_circle_demo (image): # 降噪处理 dst = cv.pyrMeanShiftFiltering(ima ...
- [JavaScript] Uncaught TypeError: Method get Set.prototype.size called on incompatible receiver
在对Set进行方法扩展的时候,无法覆盖size属性 情景:定义一个SingletonSet,继承自Set,size只能为1,并且不能add和remove //首先是extend函数 var exten ...
- HFS模板开发
痉挛模板, 节, 符号 & 变量帮助需要更多帮助 吗?看看 下面这些链接-模板是模型痉挛用于构建 HTML 页面. -它分为几个部分, 每个部分描述最终 HTML 页面的一部分. -此模板必须 ...
- 梦想CAD控件网页版标注样式
增加标注样式 _DMxDrawX::AddDimStyle 增加一个新的标注样式,如果当前已经有指定名的标注样式,就直接失败返回.详细说明如下: 参数 说明 BSTR pszName 新增加的标注样式 ...
- java_IO_装饰器
装饰器模式 装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.这种类型的设计模式属于结构型模式,它是作为现有的类的一个包装. 这种模式创建了一个装饰 ...
- Django线上部署教程:腾讯云+Ubuntu+Django+Uwsgi(转载)
网站名称: 向东的笔记本 本文链接: https://www.eastnotes.com/post/29 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议.转载请注明出处! ...
- layer弹出层无法关闭问题
parent.layer.closeAll();如果关闭指定弹出层,获取对应弹出层的索引,进行关闭
- 王垠代表作《完全用Linux工作》
完全用Linux工作-王垠 <完全用Linux工作>作者:王垠 完全用 GNU/Linux 工作 理解 GNU/Linux 更多精彩请直接访问SkySeraph个人站点:www.sky ...
- 「 CODE[VS] P2853 」 方格游戏
题目大意 给定一张 $n\times n$ 的网格.每个格子上都有一个系数 $a$,先下 $A$ 和 $B$ 两人选择两条 $(1,1)\rightarrow (n,n)$ 路径.要求着两条路径不能相 ...
- TestNG套件测试(一)
测试套件是用于测试软件程序的行为或一组行为的测试用例集合. 在TestNG中,我们无法在测试源代码中定义一个套件,但它可以由一个XML文件表示,可以灵活配置要运行的测试. 套件用<suite&g ...