/
routable.ts
87 lines (75 loc) 路 2.11 KB
/
routable.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Vue } from '../components/Vuetify'
import { VNodeData } from 'vue/types'
import Ripple from '../directives/ripple'
export default Vue.extend({
name: 'routable',
directives: {
Ripple
},
props: {
activeClass: String,
append: Boolean,
disabled: Boolean,
exact: {
type: Boolean,
default: undefined
},
exactActiveClass: String,
href: [String, Object],
to: [String, Object],
nuxt: Boolean,
replace: Boolean,
ripple: [Boolean, Object],
tag: String,
target: String
},
methods: {
/* eslint-disable-next-line no-unused-vars */
click (e: MouseEvent): void { /**/ },
generateRouteLink () {
let exact = this.exact
let tag
const data: VNodeData = {
attrs: { disabled: this.disabled },
class: (this as any).classes,
props: {},
directives: [{
name: 'ripple',
value: (this.ripple && !this.disabled) ? this.ripple : false
}] as any, // TODO
[this.to ? 'nativeOn' : 'on']: {
...this.$listeners,
click: this.click
}
}
if (typeof this.exact === 'undefined') {
exact = this.to === '/' ||
(this.to === Object(this.to) && this.to.path === '/')
}
if (this.to) {
// Add a special activeClass hook
// for component level styles
let activeClass = this.activeClass
let exactActiveClass = this.exactActiveClass || activeClass
if ((this as any).proxyClass) {
activeClass += ' ' + (this as any).proxyClass
exactActiveClass += ' ' + (this as any).proxyClass
}
tag = this.nuxt ? 'nuxt-link' : 'router-link'
Object.assign(data.props, {
to: this.to,
exact,
activeClass,
exactActiveClass,
append: this.append,
replace: this.replace
})
} else {
tag = (this.href && 'a') || this.tag || 'a'
if (tag === 'a' && this.href) data.attrs!.href = this.href
}
if (this.target) data.attrs!.target = this.target
return { tag, data }
}
}
})