domStreams enable you to pass additional data along the stream that can be provided by the template (such as data coming from a v-forrendering of an Array). You can then pluck off the data from the stream and use it further down the stream.

<template>
<section class="section">
<button class="button" :disabled="disabled$" v-stream:click="{subject: click$, data: 1}">{{buttonText$}}</button>
<h2>
{{name$}}
</h2>
<img v-stream:error="imageError$" :src="data:image$" alt="">
</section>
</template> <script>
import { from, of, merge, throwError } from 'rxjs';
import {
exhaustMap,
switchMap,
pluck,
map,
mapTo,
catchError,
shareReplay,
share,
startWith
} from 'rxjs/operators'; export default {
name: 'app',
domStreams: ['click$', 'imageError$'],
subscriptions() {
const createLoader = url => from(this.$http.get(url)).pipe(pluck('data')); const luke$ = this.click$.pipe(
pluck('data'),
map(id => `https://starwars.egghead.training/people/${id}`),
exhaustMap(createLoader),
catchError(() => of({name: 'Failed.. :('})),
share()
); const name$ = luke$.pipe(pluck('name')); const loadImage$ = luke$.pipe(
pluck('image'),
map(src => `https://starwars.egghead.training/${src}`)
); const failImage$ = this.imageError$.pipe(
mapTo(`http://via.placeholder.com/400x400`)
); const image$ = merge(
loadImage$,
failImage$
) const disabled$ = merge(
this.click$.pipe(mapTo(true)),
luke$.pipe(mapTo(false)),
).pipe(startWith(false)); const buttonText$ = disabled$.pipe(map(b => (b ? 'Loading...' : 'Load'))); return {
name$,
image$,
failImage$,
disabled$,
buttonText$
};
}
};
</script>

[Vue-rx] Pass Template Data Through domStreams in Vue.js and RxJS的更多相关文章

  1. [Vue @Component] Pass Props Between Components with Vue Slot Scope & renderless component

    Components with slots can expose their data by passing it into the slot and exposing the data using  ...

  2. Vue 数组 字典 template v-for 的使用

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. [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 ...

  4. Vue学习笔记 template methods,filters,ChromeDriver,安装sass

    ChromeDriver installation failed Error with http(s) request: Error: connect ETIMEDOUT 172.217.160.80 ...

  5. Kendo-Grid for Vue API and Template

    写此博客的原因:在做项目时前端用的vue,后端用的jfinal.在前端veu中调用了kendo grid插件,但是在官方文档中对kendo grid for vue 的api和template都不太详 ...

  6. [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available

    原文链接https://blog.csdn.net/xiaomajia029/article/details/88320233 问题描述: 原因分析:在项目配置的时候,默认 npm 包导出的是运行时构 ...

  7. vue组件中的data与methods

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> ...

  8. 15.Vue组件中的data

    1.组件中展示数据和响应事件: // 1. 组件可以有自己的 data 数据 // 2. 组件的 data 和 实例的 data 有点不一样,实例中的 data 可以为一个对象 // 3. 但是组件中 ...

  9. Vue中用props给data赋初始值遇到的问题解决

    Vue中用props给data赋初始值遇到的问题解决 更新时间:2018年11月27日 10:09:14   作者:yuyongyu    我要评论   这篇文章主要介绍了Vue中用props给dat ...

随机推荐

  1. Canvas入门笔记-实现极简画笔

    今天学习了Html5 Canvas入门,已经有大神写得很详细了http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html#8 在学习过后 ...

  2. Mantis 配置与使用学习

    转载自:http://blog.csdn.net/xifeijian/article/category/1429687

  3. Quartus 12的TimeQuest Timing Analyzer

    Quartus 12的TimeQuest Timing Analyzer 1.在Quartus II软件打开和设置设计 安装路径下\qdesigns\fir_fliter文件.在Processing ...

  4. Magento 多站点多域名安装教程(可以设置手机模版哟,亲 \(^o^)/)

    这篇文章是安装magento子域名的教程,请先进行安装之前,确认以下几点: 1.请先确认子域名是否已经指向你的服务器 2.可以编辑.htaccess文件 3. 熟悉Cpanel操作 我们的目标是建立一 ...

  5. (转)淘淘商城系列——使用solrj来测试索引库

    http://blog.csdn.net/yerenyuan_pku/article/details/72892280 我们使用solrj来操作索引库,一般习惯先建一个单元测试类测试下增删改查方法是否 ...

  6. C# 绘图三种方式

    如果你想在窗体上进行绘画.通常会使用以下方法. 方法1,利用控件或窗体的paint事件中的painEventArgs private void form1_Paint(object sender, P ...

  7. vue基础---表单输入绑定

    [一]基础用法 用 v-model 指令在表单 <input>.<textarea> 及 <select> 元素上创建双向数据绑定.它会根据控件类型自动选取正确的方 ...

  8. python socket实现文件传输(防粘包)

    1.文件传输的要点: 采用iterator(迭代器对象)迭代读取,提高读取以及存取效率: 通过for line in file_handles逐行conn.send(): 2.socket粘包问题: ...

  9. python爬虫25 | 爬取下来的数据怎么保存? CSV 了解一下

    大家好 我是小帅b 是一个练习时长两年半的练习生 喜欢 唱! 跳! rap! 篮球! 敲代码! 装逼! 不好意思 我又走错片场了 接下来的几篇文章 小帅b将告诉你 如何将你爬取到的数据保存下来 有文本 ...

  10. 【tips】自动化测试工具 - selenium和phantomJS

    ### 目录清单 selenium和phantomjs概述 selenium常用API 案例操作:模拟登陆csdn 1. selenium和phantomJS是什么东西 selenium是一套web网 ...