Skip to content

Commit ffb48cb

Browse files
committed
add register plugin hooks
1 parent fa4eb42 commit ffb48cb

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

template/src/common/registerHooks.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* register plugins hooks for vue component
3+
*/
4+
5+
import { Component } from 'vue-property-decorator'
6+
7+
Component.registerHooks([
8+
'beforeRouteEnter',
9+
'beforeRouteLeave'
10+
])

template/src/components/views/home/home.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,15 @@ export default class Home extends Vue {
1616
let res = await this.api.getPackage({})
1717
console.log(res.content)
1818
}
19+
20+
beforeRouteEnter (to, from, next) {
21+
console.log('before home enter')
22+
next()
23+
}
24+
25+
beforeRouteLeave (to, from, next) {
26+
console.log('before home leave')
27+
next()
28+
}
1929
}
2030

template/src/main.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22
import 'vue-svgicon/dist/polyfill'
33
{{/ie}}
44
import Vue from 'vue'
5-
import App from 'components/pages/app'
5+
6+
// register plugins hooks fo vue component
7+
import 'common/registerHooks'
8+
9+
import * as svgicon from 'vue-svgicon'
10+
// import all icons
11+
import 'components/icons'
12+
613
import router from 'router'
7-
import svgicon = require('vue-svgicon')
814
{{#vuex}}
915
import store from 'store'
1016
{{/vuex}}
1117

18+
import App from 'components/pages/app'
19+
1220
// import all icons
1321
import 'components/icons'
1422
Vue.use(svgicon, {
@@ -23,4 +31,3 @@ new Vue({
2331
{{/vuex}}
2432
render: h => h(App)
2533
})
26-

0 commit comments

Comments
 (0)