File tree 5 files changed +56
-2
lines changed
5 files changed +56
-2
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <!-- eslint-disable vue/require-component-is -->
3
+ <component v-bind =" linkProps(to)" >
4
+ <slot ></slot >
5
+ </component >
6
+ </template >
7
+
8
+ <script >
9
+ import { isExternal } from ' @/utils/validate.js'
10
+ export default {
11
+ name: ' Link' ,
12
+ props: {
13
+ to: {
14
+ type: String ,
15
+ required: true
16
+ }
17
+ },
18
+ methods: {
19
+ linkProps (url ) {
20
+ if (isExternal (url)) {
21
+ return {
22
+ is: ' a' ,
23
+ href: url,
24
+ target: ' _black' ,
25
+ rel: ' noopener'
26
+ }
27
+ }
28
+ return {
29
+ is: ' router-link' ,
30
+ to: url
31
+ }
32
+ }
33
+ }
34
+ }
35
+ </script >
36
+
37
+ <style lang="scss" scoped>
38
+
39
+ </style >
Original file line number Diff line number Diff line change 1
1
export default {
2
2
app : {
3
- welcome : 'Welcome to Your Vue.js App'
3
+ welcome : 'Welcome to Your Vue.js App' ,
4
+ vueOfficialWebsite : 'vue Official Website'
4
5
}
5
6
}
Original file line number Diff line number Diff line change 1
1
export default {
2
2
app : {
3
- welcome : '欢迎来到Vue世界'
3
+ welcome : '欢迎来到Vue世界' ,
4
+ vueOfficialWebsite : 'vue 官方网站'
4
5
}
5
6
}
Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ * @param path
4
+ * @returns {boolean }
5
+ */
6
+ export function isExternal ( path ) {
7
+ return / ^ ( h t t p s ? : | m a i l t o : | t e l : | f t p : ) / . test ( path )
8
+ }
Original file line number Diff line number Diff line change 2
2
<div >
3
3
<p >{{msg}}</p >
4
4
<p >{{$t('app.welcome')}}</p >
5
+ <app-link to =" https://vuejs.org/" >{{$t('app.vueOfficialWebsite')}}</app-link >
5
6
</div >
6
7
</template >
7
8
8
9
<script >
10
+ import AppLink from ' @/components/Link/index'
9
11
export default {
10
12
name: ' index' ,
11
13
data () {
12
14
return {
13
15
msg: ' i am vue demo'
14
16
}
17
+ },
18
+ components: {
19
+ AppLink
15
20
}
16
21
}
17
22
</script >
You can’t perform that action at this time.
0 commit comments