提交 | 用户 | age
|
2a61f6
|
1 |
<template> |
L |
2 |
<component :is="type" v-bind="linkProps(to)"> |
|
3 |
<slot /> |
|
4 |
</component> |
|
5 |
</template> |
|
6 |
|
|
7 |
<script> |
|
8 |
import { isExternal } from '@/utils/validate' |
|
9 |
|
|
10 |
export default { |
|
11 |
props: { |
|
12 |
to: { |
|
13 |
type: String, |
|
14 |
required: true |
|
15 |
} |
|
16 |
}, |
|
17 |
computed: { |
|
18 |
isExternal() { |
|
19 |
return isExternal(this.to) |
|
20 |
}, |
|
21 |
type() { |
|
22 |
if (this.isExternal) { |
|
23 |
return 'a' |
|
24 |
} |
|
25 |
return 'router-link' |
|
26 |
} |
|
27 |
}, |
|
28 |
methods: { |
|
29 |
linkProps(to) { |
|
30 |
if (this.isExternal) { |
|
31 |
return { |
|
32 |
href: to, |
|
33 |
target: '_blank', |
|
34 |
rel: 'noopener' |
|
35 |
} |
|
36 |
} |
|
37 |
return { |
|
38 |
to: to |
|
39 |
} |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
</script> |