-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
43 lines (42 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
install: function install(Vue) {
var options =
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var directiveName = options.name || "ref";
Vue.directive(directiveName, {
bind: function bind(el, binding, vnode) {
Vue.nextTick(function() {
binding.value(vnode.componentInstance || el, vnode.key);
});
binding.value(vnode.componentInstance || el, vnode.key);
},
update: function update(el, binding, vnode, oldVnode) {
if (oldVnode.data && oldVnode.data.directives) {
var oldBinding = oldVnode.data.directives.find(function(directive) {
var name = directive.name;
return name === directiveName;
});
if (oldBinding && oldBinding.value !== binding.value) {
oldBinding && oldBinding.value(null, oldVnode.key);
binding.value(vnode.componentInstance || el, vnode.key);
return;
}
}
// Should not have this situation
if (
vnode.componentInstance !== oldVnode.componentInstance ||
vnode.elm !== oldVnode.elm
) {
binding.value(vnode.componentInstance || el, vnode.key);
}
},
unbind: function unbind(el, binding, vnode) {
binding.value(null, vnode.key);
}
});
}
};