1.全局的自定义指令

实现:当页面刷新时,光标聚焦到搜索框中

            <label>
搜索:
<input type="text" class="form-control" v-model="keywords" v-getfocus/>
</label>
<script>
//参数1:指令的名字 在定义时 指令之前不需要加上 v- 的前缀,调用的时候需要加上 v-
Vue.directive('getfocus', {
//el表示被绑定的那个元素对象
bind: function(el) { //没当指令绑定到元素上时,会立即执行这个bind函数,只执行一次
//el.focus()
},
inserted: function(el) { //表示元素插入到 DOM中的时候,会执行inserted函数,只执行一次
//只用当一个元素插入DOM之后,才能获取焦点
el.focus() },
updated: function(el) { //当VNode跟新的收,会执行updated,可以多次触发 }
}); </script>

2.私有自定义指令

实现:改变字体和颜色

<h1 v-color="'red'" v-fontsize="100">我是私有的自定义指令</h1>
<script>
var vm = new Vue({
el: '#app',
data: {},
methods: {
directives: { //自定义私有指令
'color': {
bind: function(el, binding) {
el.style.color = binding.value }
},
'fontsize': function(el, binding) {//function等同于把代码写到bind和update中去
el.style.fontSize =parseInt(binding.value) +'px' }
}
});
</script>

3.自定义键盘修饰符

Vue.js定义好了的

.enter  .tab  .delete (捕获 “删除” 和 “退格” 键)  .esc  .space  .up  .down  .left  .right   .ctrl  .alt  .shift

为定义的修饰符需要自己定义

             <label>
Name:
<input type="text" class="form-control" v-model="name" @keyup.113="add()"/>
</label>
//自定义键盘修饰符F2
Vue.config.keyCodes.f2 = 113;
ey Code
backspace 8
tab 9
enter 13
shift 16
ctrl 17
alt 18
pause/break 19
caps lock 20
escape 27
page up 33
page down 34
end 35
home 36
left arrow 37
up arrow 38
right arrow 39
down arrow 40
insert 45
delete 46
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
a 65
b 66
c 67
d 68
 
Key Code
e 69
f 70
g 71
h 72
i 73
j 74
k 75
l 76
m 77
n 78
o 79
p 80
q 81
r 82
s 83
t 84
u 85
v 86
w 87
x 88
y 89
z 90
left window key 91
right window key 92
select key 93
numpad 0 96
numpad 1 97
numpad 2 98
numpad 3 99
numpad 4 100
numpad 5 101
numpad 6 102
numpad 7 103
 
Key Code
numpad 8 104
numpad 9 105
multiply 106
add 107
subtract 109
decimal point 110
divide 111
f1 112
f2 113
f3 114
f4 115
f5 116
f6 117
f7 118
f8 119
f9 120
f10 121
f11 122
f12 123
num lock 144
scroll lock 145
semi-colon 186
equal sign 187
comma 188
dash 189
period 190
forward slash 191
grave accent 192
open bracket 219
back slash 220
close braket 221
single quote 222
   

vue.js_06_vue.js的自定义指令和自定义键盘修饰符的更多相关文章

  1. vue 2.x 的 v-bind 指令的 .prop 事件修饰符详解

    vue 官方文档对 .prop 修饰符的解释是: 使用例子: 那么,具体的原理和用法是什么呢?这要从 html 的 DOM node 说起. 在 html 标签里,我们可以定义各种 attribute ...

  2. 从零开始学 Web 之 Vue.js(二)过滤器,按键修饰符,自定义指令

    大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...

  3. Vue自定义指令和自定义过滤器

    一.自定义指令: 自定义指令分为两种:全局自定义指令和局部自定义指令 全局指令指所有组件都可以使用,局部指令是只有在当前组件中才可以使用. 如,我们现在有个需求,当一个输入框获取焦点时,显示出一个di ...

  4. Vue学习笔记【13】——键盘修饰符以及自定义键盘修饰符

    1.x版本中自定义键盘修饰符[了解] Vue.directive('on').keyCodes.f2 = 113; 2.x版本中自定义键盘修饰符 通过Vue.config.keyCodes.名称 = ...

  5. vue--键盘修饰符以及自定义键盘修饰符

    键盘修饰符以及自定义键盘修饰符 1.vue键盘修饰符[了解即可] ​地址:https://cn.vuejs.org/v2/guide/events.html#%E6%8C%89%E9%94%AE%E4 ...

  6. [Vue] : 键盘修饰符

    键盘修饰符以及自定义键盘修饰符 为文本框回车键绑定事件 <input type="text" class="form-control" v-model=& ...

  7. Vue 监听键盘,键盘修饰符keyup

    附录:键盘Key Code对照表 代码: <!doctype html> <html lang="en"> <head> <meta ch ...

  8. vue.js之过滤器,自定义指令,自定义键盘信息以及监听数据变化

    一.监听数据变化 1.监听数据变化有两种,深度和浅度,形式如下: vm.$watch(name,fnCb); //浅度 vm.$watch(name,fnCb,{deep:true}); //深度监视 ...

  9. vue.js 四(指令和自定义指令)

    官方的指令说明已经很简单了,这里再写一遍,也是自己加深一下印象 v-text 就是写入单纯的文本,可以忽略这个指令直接双花括号代替 <span v-text="msg"> ...

随机推荐

  1. 【未完成】Jmeter接口自动化测试:参数化设置

    1. 从CSV文件读取参数 创建一个CVS文件,文件第一行不写参数名,直接从参数值开始,每一列代表一个参数 在测试计划或者线程组中,添加一个配置元件-->CSV 数据文件设置 Filename: ...

  2. 暴力贪心+预处理自动机——cf990E

    枚举每种灯管,然后找到代价最小的那种灯管 贪心策略:灯管从0开始向右放置,如果末尾是不能放置灯管的结点,那么要往回找到最近一个可以放置灯管的结点,在那里放置灯管 所以先预处理每个不能放置灯管的结点对应 ...

  3. 计算几何——圆卡精度cf1059D

    double 在1e17以后就不能顾及小数,所以用一下加精度的技巧 sqrt(r*r-d*d)=sqrt(r+d)*sqrt(r-d) 遇到误差在几位以内的注意要修改二分的精度,用最大的数据去乘以精度 ...

  4. mac 10.9 install cocoapods issue

    If you've installed the OS X Mavericks Beta and you're having ruby issues like this: /System/Library ...

  5. C#,判断数字集合是否是连续的

    /// <summary> /// 判断数字集合是否是连续的 /// </summary> /// <returns></returns> public ...

  6. try-catch 捕捉不到异常

    code: int _tmain(int argc, _TCHAR* argv[]) { cout << "In main." << endl;  //定义 ...

  7. 海量数据解决思路之Hash算法

    海量数据解决思路之Hash算法   一.概述 本文将粗略讲述一下Hash算法的概念特性,里边会结合 分布式系统负载均衡 实例对Hash的一致性做深入探讨.另外,探讨一下Hash算法在海量数据处理方案中 ...

  8. Web中常见的绕过和技巧

    SQL注入 十六进制绕过引号 slect table_name from information_schema.table where table_schema="sqli"; s ...

  9. Collection单列集合中的常用实现类

    Collection 集合层次的根接口 List 有序 有索引 可以重复 ArrayList 底层数据结构是数组 查询快 增删快 线程不安全 效率高 LinkedList 底层数据结构是链表 查询慢 ...

  10. 18-4-bind

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...