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. Spring Boot (27) actuator服务监控与管理

    actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...

  2. 【hive】hive表很大的时候查询报错问题

    线上hive使用环境出现了一个奇怪的问题,跑一段时间就报如下错误: FAILED: SemanticException MetaException(message:Exception thrown w ...

  3. linux 常用shell命令之wc

    wc:查看文件统计信息 用法:$ wc filename 1. $ wc fileName $ wc fileName X Y Z /Desktop/hello X:表示行数 Y:表示单词数 Z:表示 ...

  4. Unity笔记(3)自学第二天

    学习记录: 界面使用: 脚本使用: 脚本注意点:

  5. Android Could not find com.afollestad:material-dialogs:0.7.6.0 解决

    AS报错:Could not find com.afollestad:material-dialogs:0.7.6.0 网上没有解决方案: 解决: 将用: compile('com.afollesta ...

  6. PHP开发心得四

    1,php返回给html页面的Json数据不能含有回车符 某次用php编写查询数据库数据,以json格式返回给前端页面js文件,js文件以angularJS的函数调用处理的方式进行数据显示,但数据返回 ...

  7. parsley之验证属性设置

    parsley.js添加表单验证功能,直接在html元素中添加对应属性: Name API Description Required #2.0必填 required HTML5 data-parsle ...

  8. swift protocol 与类继承结合时的bug

    protocol CommonTrait: class { func commonBehavior() -> String } extension CommonTrait { func comm ...

  9. java.lang.NoClassDefFoundError: org/hibernate/validator/internal/engine/DefaultClockProvider

    ①在springboot的spring-boot-starter-web默认引入了以下依赖: <dependency> <groupId>com.fasterxml.jacks ...

  10. 09Oracle Database 数据表数据插入,更新,删除

    Oracle Database 数据表数据插入,更新,删除 插入数据 Insert into table_name(column) values(values); insert into studen ...