vue2 + typescript2 自定义过滤器
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 自定义过滤器的更多相关文章
- vue2.0 自定义过滤器(filter)实例
一.过滤器简介 (1)过滤器创建 过滤器的本质 是一个有参数 有返回值的方法 new Vue({ filters:{ myCurrency:function(myInput){ return 处理后的 ...
- vue2.0 自定义过滤器
2.0中已经废弃了过滤器,需要我们自定义 <div id="app"> {{message|uppercase}} </div> //过滤器 Vue.fil ...
- VueJs 自定义过滤器使用总结
过滤器是一个通过输入数据,能够及时对数据进行处理并返回一个数据结果的简单函数.Vue有很多很便利的过滤器,可以参考官方文档, http://cn.vuejs.org/api/#过滤器 ,过滤器通常会使 ...
- vue.js学习 自定义过滤器使用(1)
在这个教程中,我们将会通过几个例子,了解和学习VueJs的过滤器.我们参考了一些比较完善的过滤器,比如orderBy 和 filterBy.而且我们可以链式调用过滤器,一个接一个过滤.因此,我们可以定 ...
- vue-cli 自定义过滤器的使用
vue-cli 自定义过滤器的使用 vue2.0将内置过滤器去除,所以过滤器需要自己编写. Vue.js 允许你自定义过滤器,可被用作一些常见的文本格式化.过滤器可以用在两个地方:mustache 插 ...
- vue中自定义指令vue.direvtive,自定义过滤器vue.filter(),vue过渡transition
自定义指令 默认设置的核心指令( v-model,v-bind,v-for,v-if,v-on等 ),Vue 也允许注册自定义指令.注意,在 Vue2.0 里面,代码复用的主要形式和抽象是组件——然而 ...
- 实现MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器
MVC开发中几种以AOP方式实现的Filters是非常好用的,默认情况下,我们通过App_Start中的FilterConfig来实现的过滤器注册是全局的,也就是整个应用程序都会使用的,针对单独的Fi ...
- lucene自定义过滤器
先介绍下查询与过滤的区别和联系,其实查询(各种Query)和过滤(各种Filter)之间非常相似,可以这样说只要用Query能完成的事,用过滤也都可以完成,它们之间可以相互转换,最大的区别就是使用过滤 ...
- asp.net MVC之 自定义过滤器(Filter) - shuaixf
一.系统过滤器使用说明 1.OutputCache过滤器 OutputCache过滤器用于缓存你查询结果,这样可以提高用户体验,也可以减少查询次数.它有以下属性: Duration :缓存的时间, 以 ...
随机推荐
- TOJ3031: Multiple bfs
3031: Multiple Time Limit(Common/Java):2000MS/6000MS Memory Limit:65536KByte Total Submit: 60 ...
- 使用sami生成文档
从composer安装sami $ composer require sami/sami composer自动配置完以后,可以先测试一下是否安装成功.只要不带参数的运行一下sami,就会知道结果. $ ...
- 用Navicat Premium快速查看mysql数据库版本信息
在出现的界面输入命令 select version();
- 【Kubernetes】The connection to the server <master>:6443 was refused - did you specify the right host or port?
不知道怎么用着用着,使用kubectl 时报错,错误如下: root@R740--:~# kubectl get pod The connection to the server 107.105.13 ...
- Java中接口的作用
转载于:https://www.zhihu.com/question/20111251 困惑:例如我定义了一个接口,但是我在继承这个接口的类中还要写接口的实现方法,那我不如直接就在这个类中写实现方法岂 ...
- bzoj 4566 [Haoi2016]找相同字符SA
4566: [Haoi2016]找相同字符 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 128 Solved: 75[Submit][Status ...
- VMware 11 安装Mac 10.9
VMware Workstation 11, 10, 9 and 8 Unlocker to Run Mac OS X Guests in Windows 8.1 and 7 VM10装Mac OS ...
- LeetCode OJ——Convert Sorted Array to Binary Search Tree
http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 将一个升序的数组转换成 height balan ...
- html5(拖拽2)
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 对农行金e顺k令的一些猜测
手上有一个未激活的农行金e顺k令 开机后要求输入12位的激活码,随机输入多次,均告失败 花了点时间猜想k令的工作模式: 已知: k令无法联网,出厂后除了输入激活码的机会外,无法获取任何信息 k令内部有 ...