1.定义一个过滤器

// color-directive.ts

import { DirectiveOptions } from 'vue'

const directive: DirectiveOptions = {
inserted(el, node) {
/**
* Using value:
* v-colorDirective={color: 'red', backgroundColor: 'blue'}
*/
if (node.value) {
el.style.backgroundColor = node.value.backgroundColor;
el.style.color = node.value.color;
} /**Using modifiers:
* v-colorDirective.color
* v-colorDirective.backgroundColor
*/
if (node.modifiers.color){
el.style.color = node.value;
} if (node.modifiers.backgroundColor) {
el.style.backgroundColor = node.value;
}
}
}; export default directive;

2.使用

<template>
<div class="hello">
<h1 v-colorDirective="{color: 'red', backgroundColor: 'blue'}">{{ message }}</h1>
<button @click="clicked">Click</button>
<router-link to="/hello-ts">Hello Ts</router-link>
</div>
</template> <script lang="ts">
import Vue from 'vue'
import Component from 'vue-class-component'
import colorDirective from '../color-directive'; @Component({
directives: {
colorDirective
}
})
export default class Hello extends Vue {
....
}
<template>
<div>
<h3 v-colorDirective.color="'green'">HelloTs</h3>
<router-link to="/">Hello</router-link>
</div>
</template>
<script lang="ts"> import Vue from 'vue'
import Component from 'vue-class-component'
import colorDirective from '../color-directive'; @Component({
directives: {
colorDirective
}
})
export default class HelloTs extends Vue {
...
}

.

vue2 + typescript2 自定义过滤器的更多相关文章

  1. vue2.0 自定义过滤器(filter)实例

    一.过滤器简介 (1)过滤器创建 过滤器的本质 是一个有参数 有返回值的方法 new Vue({ filters:{ myCurrency:function(myInput){ return 处理后的 ...

  2. vue2.0 自定义过滤器

    2.0中已经废弃了过滤器,需要我们自定义 <div id="app"> {{message|uppercase}} </div> //过滤器 Vue.fil ...

  3. VueJs 自定义过滤器使用总结

    过滤器是一个通过输入数据,能够及时对数据进行处理并返回一个数据结果的简单函数.Vue有很多很便利的过滤器,可以参考官方文档, http://cn.vuejs.org/api/#过滤器 ,过滤器通常会使 ...

  4. vue.js学习 自定义过滤器使用(1)

    在这个教程中,我们将会通过几个例子,了解和学习VueJs的过滤器.我们参考了一些比较完善的过滤器,比如orderBy 和 filterBy.而且我们可以链式调用过滤器,一个接一个过滤.因此,我们可以定 ...

  5. vue-cli 自定义过滤器的使用

    vue-cli 自定义过滤器的使用 vue2.0将内置过滤器去除,所以过滤器需要自己编写. Vue.js 允许你自定义过滤器,可被用作一些常见的文本格式化.过滤器可以用在两个地方:mustache 插 ...

  6. vue中自定义指令vue.direvtive,自定义过滤器vue.filter(),vue过渡transition

    自定义指令 默认设置的核心指令( v-model,v-bind,v-for,v-if,v-on等 ),Vue 也允许注册自定义指令.注意,在 Vue2.0 里面,代码复用的主要形式和抽象是组件——然而 ...

  7. 实现MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器

    MVC开发中几种以AOP方式实现的Filters是非常好用的,默认情况下,我们通过App_Start中的FilterConfig来实现的过滤器注册是全局的,也就是整个应用程序都会使用的,针对单独的Fi ...

  8. lucene自定义过滤器

    先介绍下查询与过滤的区别和联系,其实查询(各种Query)和过滤(各种Filter)之间非常相似,可以这样说只要用Query能完成的事,用过滤也都可以完成,它们之间可以相互转换,最大的区别就是使用过滤 ...

  9. asp.net MVC之 自定义过滤器(Filter) - shuaixf

    一.系统过滤器使用说明 1.OutputCache过滤器 OutputCache过滤器用于缓存你查询结果,这样可以提高用户体验,也可以减少查询次数.它有以下属性: Duration :缓存的时间, 以 ...

随机推荐

  1. jmeter所有版本下载路径

    https://archive.apache.org/dist/jmeter/binaries/

  2. linux内核代码注释 赵炯 第三章引导启动程序

    linux内核代码注释 第三章引导启动程序 boot目录中的三个汇编代码文件   bootsect.s和setup.s采用近似intel的汇编语法,需要8086汇编器连接器as86和ld86 head ...

  3. K-means算法的优缺点

    K-means算法的优缺点 优点:原理简单,实现容易 缺点: 收敛较慢 算法时间复杂度比较高 \(O(nkt)\) 不能发现非凸形状的簇 需要事先确定超参数K 对噪声和离群点敏感 结果不一定是全局最优 ...

  4. [办公软件篇][2]source-insight安装

    http://jingyan.baidu.com/article/a3f121e4fe173ffc9052bbb0.html 注意看:同步代码

  5. 【bzoj1690】[Usaco2007 Dec]奶牛的旅行 分数规划+Spfa

    题目描述 作为对奶牛们辛勤工作的回报,Farmer John决定带她们去附近的大城市玩一天.旅行的前夜,奶牛们在兴奋地讨论如何最好地享受这难得的闲暇. 很幸运地,奶牛们找到了一张详细的城市地图,上面标 ...

  6. ECMA-262 Extractions

    For the purpose of this article, ECMA-262 refers to ECMAScript® 2017 Language Specification. ECMAScr ...

  7. [luoguP2763] 试题库问题(最大流)

    传送门 每个类别和它所有的试题连一条权值为1的边. 增加一个超级源点s,s和每个类别连一条权值为选当前类别数量的边. 增加一个超级汇点t,每个试题和t连一条权值为1的边. 求最大流即可. ——代码 # ...

  8. android 脱壳 之 dvmDexFileOpenPartial断点脱壳原理分析

    android 脱壳 之 dvmDexFileOpenPartial断点脱壳原理分析 导语: 笔者主要研究方向是网络通信协议的加密解密, 对应用程序加固脱壳技术很少研究, 脱壳壳经历更是经历少之甚少. ...

  9. java面试题之volatile的工作原理

    volatile的特性: volatile可见性:对一个volatile的读,总可以看到对这个变量最终的写: volatile原子性:volatile对单个读/写具有原子性(32位Long.Doubl ...

  10. 【bzoj2301】[HAOI2011]Problem b 莫比乌斯反演

    Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...