1
- import VueForceNextTick from 'vue-force-next-tick'
2
1
import { OPTIONS } from './constants'
3
2
import VueAnnouncer from './vue-announcer.vue'
4
3
4
+ const draf = ( cb ) => requestAnimationFrame ( ( ) => requestAnimationFrame ( cb ) )
5
+
5
6
export default function install ( Vue , options = { } , router = null ) {
6
7
options = { ...OPTIONS , ...options }
7
8
8
- Vue . use ( VueForceNextTick )
9
9
Vue . component ( 'VueAnnouncer' , VueAnnouncer )
10
10
Vue . prototype . $announcer = {
11
11
options,
@@ -16,7 +16,7 @@ export default function install (Vue, options = {}, router = null) {
16
16
if ( politeness ) {
17
17
this . data . politeness = politeness
18
18
}
19
- Vue . $forceNextTick ( ( ) => {
19
+ draf ( ( ) => {
20
20
this . data . content = message
21
21
} )
22
22
}
@@ -40,15 +40,18 @@ export default function install (Vue, options = {}, router = null) {
40
40
// If set the router, will be announced the change of route
41
41
if ( router ) {
42
42
router . afterEach ( to => {
43
- const msg = to . meta . announcer . message || document . title . trim ( )
44
- const complement = to . meta . announcer . complementRoute || options . complementRoute
45
- const politeness = to . meta . announcer . politeness || null
46
- Vue . prototype . $announcer . set ( `${ msg } ${ complement } ` , politeness )
43
+ draf ( ( ) => { // Resolves the problem of getting the correct title when the meta announcer is not passed
44
+ const announcer = to . meta . announcer || { }
45
+ const msg = announcer . message || document . title . trim ( )
46
+ const complement = announcer . complementRoute || options . complementRoute
47
+ const politeness = announcer . politeness || null
48
+ Vue . prototype . $announcer . set ( `${ msg } ${ complement } ` , politeness )
49
+ } )
47
50
} )
48
51
}
49
52
}
50
53
51
- // auto install
54
+ // Auto install
52
55
if ( typeof window !== 'undefined' && typeof window . Vue !== 'undefined' ) {
53
56
window . Vue . use ( install )
54
57
}
0 commit comments